The specific example (e.g. the request's body-matching pattern was not satisfied?) can easily be accomplished using two different stubs with two different priorities.
The first stub would have a higher priority and be a more specific match and return the success response. The second stub would have a lower priority, essentially be a catchall for all other calls, and return the failure response.
For example, if the only difference was that you wanted all calls to "/success-endpoint" to return a 200, and any other ones to return the 400...
stubFor(get("/success-endpoint").atPriority(1)
.willReturn(ok("Success response body")));
stubFor(get(urlMatching("/.*")).atPriority(2)
.willReturn(aResponse().withStatus(400).withBody("Error response body")));
If you wanted to combine the success/error response in the same stub, you'd need to use a little more creativity. If the status code were in the request body, you could grab that using Response Template and plug it in as the response status code. If it weren't super visible and you needed to use something else in the request, you could create a Response Transformer and use that to inform your conditional response. Maybe Scenarios is something up your alley. Sorry that the rest of this response isn't super specific but instead sort of vague, but without knowing what your request/response looks like, there are a plethora of viable options.