-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add text and json fallback error handlers #1937
Conversation
I am still working on the tests, but I wanted to get this out there for some feedback ASAP so we can try and include it in upcoming release. It is not a breaking change, and a relatively minor change. |
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.
Looks great!
FWIW, the old HTML responses are actually valid HTML5.
The <!DOCTYPE html>
hint tag puts the document in HTML5-mode. In HTML5 the <html>
document wrapper tag is not needed (though most people put it in anyway for html4 backward compatibility). Also the <head>
tag is technically optional, you can just put your meta, script, title, and style tags before your content. Along the same lines, it doesn't need a <body>
tag if there's no head before it.
<p>
tags never need to be closed (some linters even generate an error for a closing </p>
tag) and finally </body>
and </html>
closing tags don't need to be present at the end of the file (they are assumed present if the HTML just ends).
I put it in a linter and it yelled at me 🤷♂️ |
long time no see, but I really like this PR. I was just wondering: what if we read the |
I like this idea. Maybe this can be the behavior for
I would suggest that would be a sensible default. But since that would be a breaking change, maybe we don't make that default until after LTS. |
hey, I like that as well! 😎 I don't know if this will add more complexity to the code (after all, "gotta go fast"), but this is just in case of an error, which is not what any developer is looking on their app (except during development, sure), so ... but, even so, I'm pretty sure that could be passed to a constructor / |
@vltr, I think the main usage of this is really for development purposes. They should be safe enough to not leak in production, but this is not intended to be a production-ready replacement for error handling. Primarily because (as mentioned in the other thread), there are too many considerations for us to be able to account for. With that said, I will keep this in mind. |
@ahopkins yeap, being just for development I think it's fine ... I just mentioned about performance because, well, never mind, that should not be the case 👍 |
I discovered the issue. Needed a single closing |
"The missing |
Ok, I think we can still push this out in this release, with default format as "html", to keep compatibility. But we'll change it to default to "auto" in v21.03. |
There are still some type-hinting mypy errors
|
Codecov Report
@@ Coverage Diff @@
## master #1937 +/- ##
==========================================
+ Coverage 92.45% 92.73% +0.28%
==========================================
Files 27 27
Lines 3100 3192 +92
Branches 555 563 +8
==========================================
+ Hits 2866 2960 +94
+ Misses 157 155 -2
Partials 77 77
Continue to review full report at Codecov.
|
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.
Go ahead and merge
If I understood the discussion and the code correctly, only the request It might be a good idea to use the |
I thought about that, but as you said, most browsers list a bunch of different options in Accept headers. Before this becomes default, we need a much smarter logic switch on this. |
I just tested Chrome, Firefox, Safari, Edge, IE11, Android-Chrome, Android-Firefox, iOS-Safari and Opera Mini, which all can be handled by The results and a quickly hacked testing page at https://browser.zi.fi/ |
Nice. @Tronic can you move this to a new issue for further development? |
Replaces #1905
PR #1768 added HTML default exception pages. This PR adds two alternative fallback exception pages: text and JSON.
This is NOT meant to replace custom error handlers, but is meant to be for fallback.
This is configurable with:
The default will still be HTML. And, the HTML page is untouched (except for some fixes to make valid HTML.
Just like in HTML, there are two handlers: one for debuggable exception responses, the other for minimal responses.
Text
JSON