mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Support returning 404 when file referenced by BodyAsFile isn't found #538
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @goldsam on GitHub (Aug 1, 2023).
Originally assigned to: @StefH on GitHub.
Is your feature request related to a problem? Please describe.
Currently, a 500 error status is returned for a stub which uses
BodyAsFileto reference a non-existent file.it would be useful to specify a 404 status could be returned instead when this occurs.
Describe the solution you'd like
The easiest solution would be to add a flag to prevent the mock from faulting and return a 500 and instead let additional mocks be evaluated. Then, a 404 fallback stub could be specified which a priority that evaluates after the stub using
BodyAsFile.Describe alternatives you've considered
Additional additional fields to support an "error" case seems unnecessary and complicated and breaks the existing paradigm.
Is your feature request supported by WireMock (java version)? Please provide details.
Don't know.
Additional context
n/a
@StefH commented on GitHub (Aug 3, 2023):
@goldsam
I'll investigate the error.
About
404: in several places in the matchers or other code, I catch exceptions, and depending on https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Matchers/IMatcher.cs#L21 I do throw an exception.However I think I need to change this behavior, and just return the exception-message in the 404 message so that in case of an exception, the caller can figure out what could be wrong.
@goldsam commented on GitHub (Aug 4, 2023):
It might nice to allow evaluation to continue to the next stub, so that the user could then stub a 404 or any other behavior they might desire. Perhaps a flag in the stub to control this?
@StefH commented on GitHub (Aug 5, 2023):
Currently the response is indeed like this:
http status 500
In that case a proposal could be like:
What are your thoughts?
@goldsam commented on GitHub (Aug 6, 2023):
That works for me, but I do think it might be adding more complexity than is necessary. You could also just add a
SkipOnExceptionflag instead and continue to the next stub when an exception occurs when set.Either way, I appreciate you giving this your attention.
@StefH commented on GitHub (Aug 9, 2023):
In this case:
The mapping is invalid (e.g. due to invalid referenced file), which results that the output mapping cannot be constructed. In that case 500 is returned.
Also for example in XPathMatcher, I've change the code so that: