In WireMock under the __files directory I have an invoices subdirectory. The number of json files in the directory changes over time.
To get an invoice I use the query like http://localhost:8080/invoices?getInvoice=81681. (The getInvoice value should match a json file in the invoices directory)
In my code I have the following stub:
stubFor(get(urlPathMatching("/invoices"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("invoices/{{request.query.getInvoice}}.json")
.withTransformers("response-template")));
When I make a request where query value matches a file in invoices I get a good response. When the request does not match I get a 500 response.
I would like to return a 404 instead of a 500. I looked for ways of having a conditional statement in my code but nothing I have tried so far works.