-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Feature - Add content type to ErrorPage #216
Comments
@LLIT , I like it! When you've had this running, does it format/return all right with the next call being Wondering if there could be a way of calling the appropriate response function (json, xml, or html) - or just assume for the error pages that the response type should be the same as the request (with html as default) |
I did some tests, and my Rest client worked, but from Powershell it sucks! I will do some more testing... |
Yeah, it'd be dependant on the client sending in the content type on the request. One thought I had was what if we had multiple file types, and pode selects the appropriate one depending on the request's content type - similar to yours and switching out the content in a single file, though this way you'd know which content type you were getting back for the response (to prevent HTML being sent as JSON because of the request's content type). Ie, 🤔 |
Managed to do some work and ideas on this one; so the idea here is like my previous comment, and the error message returned is based on the content-type supplied in the request's headers (with the default being HTML). For example, if you want to return a JSON error page for a REST API, then the It could also be possible to do this, and your idea too. Possibly through some config setting on Doing this has given me an idea though: maybe having a "default" content type that could be defined in the |
Update on this one, the default logic is to use HTML pages. Similar to the content type overriding, you can set a default content type to use for all error pages in the {
"web": {
"errorPages": {
"default": "application/json"
}
}
} Or you can enable strict content types, which will cause Pode to attempt to generate error page as the same content type in the request (or enforced by the route): {
"web": {
"errorPages": {
"strictContentTyping": true
}
}
} Or, again like setting up route content types, you can define route patterns for certain content types to use on certain routes when generating the error page: {
"web": {
"errorPages": {
"routes": {
"/api/*": "text/xml"
}
}
}
} You can also set a specific error page content type against routes directly, using the |
To be able to return a JSON error page if creating an API.
I have made a manual insert in the function: Show-PodeErrorPage
And in the default error page i detect it to return HTML/JSON
The text was updated successfully, but these errors were encountered: