Hi team, I have a question regarding handling 404....
# help
y
Hi team, I have a question regarding handling 404. I have a stub for 404 and it did return 404. I'm also aware of the default 404 if no mapping file found. In my tests, the behaviour is like a 404 no mapping found (continue to next call) rather that my application error handling of 404. Is anyone aware of this scenario or I may have done something incorrect?
t
If you’re not getting the response you expect (regardless of whether it’s a 404 or something else) it’s because another stub that’s higher up the list or higher priority has been matched to the request. The way to avoid this is to design the stubs’ matching criteria to be mutually exclusive, so that a request matching your, say, 200 response cannot match your 404 and vice versa.
y
thank you for your reply @Tom. I did get the response I wanted, the 404 stubbed response. After that, it should go to the error handling of my application like the same of other error response(401, 403..), but it simply skipped the error handling and continued the next call which seems the same behaviour as a 404 (no request mapping found). So, I'm not sure if WireMock misunderstood the cause of 404(no requesting mapping or a 404 from stub)
t
WireMock scans the stub list from top to bottom until it finds one that matches, or returns the default 404 if nothing matches. If you want 401, 403 etc. it’s usually a good idea to include specific match criteria that describe how these are arrived at e.g. the absence of an Authorization header could denote a 401.
y
My other error codes (401, 403) are all working as expected.
t
OK, I’m not sure what your question is in that case
y
Sorry for confusion, we have service A calls third party service B, A needs to handle error codes from B (4XX), the logic of handling error codes from B(XX) is the same piece of code. When we run the test case of error code 404 from B, the behaviour of service A is different from all other error codes(4XX). Service A skipped the error handling of 404 from B and proceed to next step just like the default 404 (when there is no request mapping found)
t
To be clear - service A is the code you’re testing, and service B is what you’re mocking?
y
Yes 🙂
t
I would suggest checking the request log after a specific test has run to see which actual stub was served
y
Sure, will do. Can I confirm what will be the result after a default 404 (no mapping found)?
t
The request log shows the status code that was returned as well as the ID of the stub it matched if any.
You can put a verification call in your test code too, if you want to check it programmatically
👍 1