Should I use middleware to validate the response #407
Unanswered
thedangler
asked this question in
Q&A
Replies: 1 comment
-
|
Hey @thedangler thanks for your patience! You can do it with middleware, but I would be inclined to extend Saloon's exception/failed request detection. On your connector (for global) or request you can extend a public function hasRequestFailed(Response $response): ?bool
{
if ($response->serverError() || $response->clientError()) {
return true;
}
return str_contains($response->body(), 'Server Error');
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
My responses from an endpoint are only valid if certain key values are set in the json response.
Using middleware, I'm thinking I can look for those key values and if they are not found some how set the response to 404?
That way I do not need to look for the correct key values every time I want to use that end point. I've found myself repeating some of this logic.
The middleware docs mention not to alter the response. So how do you recommend I do this?
Beta Was this translation helpful? Give feedback.
All reactions