-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.x] Add content-type for the default error renderer #2751
Conversation
So one thing I noticed is that right now we're letting the request |
That is absolutely true. In fact, it is the route that could define, what error content type to be expected. Or the user might even set the response content type based on a route param. For example, say we have a route that would usually return html, but if we add |
This is why we used the So what I'm thinking is that we need to introduce two modes into the handler. First mode is $errorHandler->forceContentType('application/json') There's a few more things we need to do with this handler. Namely add default headers for the response since it creates an entirely new response and if you need CORS headers then you'd need to extend the $errorHandler->addResponseMiddleware(function (Response $response) {
return $response->withHeader(...);
}); |
Would it be possible to set the forced content type in a route handler? I'm asking because if you mix different content types in the same route handler (or between different route handlers), then it should be possible to do that. Or do you recommend that the client does have to set the accept header correctly in that case? Concerning the response headers: one callback should be enough. Or do you think that there could be more than one "middleware"? Probably some sort of |
I don't think that's necessary. Also, I'm thinking that maybe we should modify the |
Is this PR good to go @adriansuter? or are you going to add the detect/force mode? |
I will add the force mode. |
@l0gicgate The |
Yes we should probably put it in the advanced error handling section |
This PR addresses #2749.
There is one commit 419f9bd that is actually a fix (independent of the issue).