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

Return more informative response codes

Open bethesque opened this issue 4 years ago • 2 comments
trafficstars

If no interaction with the path matches -> 404 If an interaction with the path matches but the headers/request is wrong -> 400/405 or 415

@uglyog if you can point to a test that shows how the rust one does it, it would be good to make them the same.

bethesque avatar Jun 03 '21 00:06 bethesque

The rust one is not correct either, because it returns a 500 on mismatch.

uglyog avatar Jun 03 '21 00:06 uglyog

The logic should be:

  1. Find all interactions the having a matching path
  2. If there are none:
    1. If it is an OPTIONS request, respond as per a CORS pre-flight request
    2. Otherwise, return a 404
  3. Match the request, and return the following:
    1. If there is a mismatch on the method: 405
    2. If a POST/PUT/PATCH and there is a mismatch on the content type: 415 (can skip this one)
    3. Else if a mismatch: 400 (reason for the 500 here is 400 responses may be present in the Pact file)
    4. Else return response from Pact file

uglyog avatar Jun 03 '21 00:06 uglyog