-
Notifications
You must be signed in to change notification settings - Fork 438
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
[server] [merged] Return HTTP errors in JSON format if Accept: contains application/json #488
Conversation
This seems reasonable; one comment inline about Accept header parsing. |
@sundbry would you mind rebasing and addressing the comment by jelmer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(See inline)
@sundbry this is a nice improvement. Please see inline comments and implement those slight tweaks when you find the time. |
On Wed, Feb 23, 2022 at 12:51:12PM -0800, ix5 wrote:
@ix5 commented on this pull request.
> @@ -81,6 +81,11 @@
logger = logging.getLogger("isso")
+def error_handler(env, request, error):
+ if "application/json" in request.headers["Accept"]:
I see. This would be an example header:
`Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8`
Perhaps create iterable by splitting on comma (+strip whitespace yada yada), filter out everything except `text/html` and `application/json`, then return based on first match, else text-only response.
I was hoping there was something in one of the libraries we're using that you could just reuse. Reimplementing that logic is doable but tricky - you'd also need to handle priorities and wildcards.
Jelmer
|
[server] Return HTTP errors in JSON format if Accept: contains application/json
Merged, though I had to manually override some changes. (You sadly disabled push access for maintainers to your branch, @sundbry) |
Note: Merged as bf701c8
Addresses issue #487 by returning JSON format error messages when in the request Accept: headers.
This does not affect existing client behavior as far as I can tell, from testing the /demo/index.html, it does not send Accept: application/json in the headers.