pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

Example/documentation of pact testing 500 errors

Open joeltheunknown opened this issue 4 years ago • 3 comments

Does anyone have any example or documentation of how they've contract tested 500 statuses? I've been searching a lot and couldn't find much info on contract testing 500 errors.

I'm trying to mock 500 errors for our project, but I'm getting the following error :

Failed to complete request: error.SystemException: 500 - [error_code = 500, message = INTERNAL SERVER ERROR, category = 500] Request Failed - Request processing failed; nested exception is error.SystemException: 500 - [error_code = 500, message = INTERNAL SERVER ERROR, category = 500]

The contract was created by myself, and not provided by consumer, so I'm unsure how else to configure it to match the 500 status I'm giving it. All other tests are passing fine (201, 400, 404, etc.). Just having issues with 500 errors.

joeltheunknown avatar Dec 08 '21 15:12 joeltheunknown

What's the use case for a contract testing 500? You shouldn't really ever "want" to get a 500, rather e.g. some handled 4xx where you can ideally give further information. I would be a little surprised (but have no evidence either way) if it's supported by Pact

mikegeeves avatar Dec 08 '21 16:12 mikegeeves

The app is supposed to return 500 for any db related or other system/server errors. I already covered the 400s. Just really wanted to see if it was possible in way to pact test 500. I read in couple areas to create unit tests to stimulate 500, but that's when I get the error above.

joeltheunknown avatar Dec 08 '21 18:12 joeltheunknown

You need to understand that most HTTP clients will throw an exception if they receive a 500 response. And that looks like that is what is happening.

The Pact mock server is doing exactly what you are asking it, to return a 500 response. Then whatever is handling the request is throwing this error: Failed to complete request: error.SystemException. This is in your application.

uglyog avatar Dec 08 '21 23:12 uglyog

You need to handle exceptions in your code if you want your consumer to have a nice facing behaviour, or handle exceptions in your test code, and assert the correct exception is thrown

YOU54F avatar May 12 '23 11:05 YOU54F