pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
823 stars 225 forks source link

Improve error message output #484

Open mefellows opened 7 months ago

mefellows commented 7 months ago

When there is a request mismatch in a consumer test, the error message is hidden away in the logs or in the response to the failing API test:

HTTP/1.1 500 Internal Server Error
access-control-allow-origin: *
content-type: application/json; charset=utf-8
x-pact: Request-Mismatch
content-length: 747
date: Tue, 28 Nov 2023 15:53:22 GMT

{"error":"Request-Mismatch : HttpRequest { method: \"POST\", path: \"/address\", query: None, headers: Some({\"content-length\": [\"192\"], \"host\": [\"localhost:9876\"], \"content-type\": [\"application/json; charset=utf-8\"]}), body: Present(b\"{\\\"Id\\\":\\\"3514466e-3e58-48b3-ab35-e553b91aa2b3\\\",\\\"AddressType\\\":\\\"delivery\\\",\\\"Street\\\":\\\"Main Street\\\",\\\"Number\\\":123,\\\"City\\\":\\\"Beverly Hills\\\",\\\"ZipCode\\\":90210,\\\"State\\\":\\\"California\\\",\\\"Country\\\":\\\"United States\\\"}\", Some(ContentType { main_type: \"application\", sub_type: \"json\", attributes: {\"charset\": \"utf-8\"}, suffix: None }), None), matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }"}

Ideally, this is pretty printed and logged to console (or whatever logging framework is configured). For example, in Pact JS it would be something like this:

  Mock server failed with the following mismatches:

    0) The following request was incorrect:

                POST /test

             1.0    $: Failed to parse the expected body as a MIME multipart body: 'no boundary in content-type'