-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: nicer error pages for HTML responses #11210
Conversation
If the request accepts an HTML Response, respond a nice error page. Allow multiple body assertions in tck.
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.
I couldn't comment directly in the diff for https://github.com/micronaut-projects/micronaut-core/blob/b057c7457fb34429649b0967b1994f3dcc1ec0f0/http-server/src/main/java/io/micronaut/http/server/exceptions/response/DefaultHtmlBodyErrorResponseProvider.java for some reason
But this class should use a concurrent linked hash map to avoid growing too big or attacks where someone specifies infinite locales and thus filling memory
...er/src/main/java/io/micronaut/http/server/exceptions/response/BodyErrorResponseProvider.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/micronaut/http/server/exceptions/response/DefaultErrorResponseProcessor.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/micronaut/http/server/exceptions/response/DefaultErrorResponseProcessor.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/micronaut/http/server/exceptions/response/DefaultErrorResponseProcessor.java
Outdated
Show resolved
Hide resolved
.../java/io/micronaut/http/server/exceptions/response/DefaultJsonBodyErrorResponseProvider.java
Outdated
Show resolved
Hide resolved
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.
@graemerocher, I have removed the SVG maps and replaced them with CSS, which has a similar effect. I did this to reduce the size of the file. With an SVG for every status code, the size was more than 1Mb.
You should now be able to see the file in the GitHub Pull-Request review.
...rc/main/java/io/micronaut/http/server/exceptions/response/DefaultErrorResponseProcessor.java
Outdated
Show resolved
Hide resolved
.../java/io/micronaut/http/server/exceptions/response/DefaultHtmlErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
.../java/io/micronaut/http/server/exceptions/response/DefaultHtmlErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
.../java/io/micronaut/http/server/exceptions/response/DefaultHtmlErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
...er/src/main/java/io/micronaut/http/server/exceptions/response/ErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/micronaut/http/server/exceptions/response/DefaultErrorResponseProcessor.java
Outdated
Show resolved
Hide resolved
*/ | ||
@Internal | ||
@Singleton | ||
final class DefaultHtmlErrorResponseBodyProvider implements HtmlErrorResponseBodyProvider<String> { |
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.
Maybe all the templates can be a property, so a user can override it?
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.
I made the class internal. If I want to the class extendable I would make it non internal. For now, I think you can provide your own implementation of HtmlErrorResponseBodyProvider
if you want to customize it. Or provide localization for other languages.
.../java/io/micronaut/http/server/exceptions/response/DefaultJsonErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
...er/src/main/java/io/micronaut/http/server/exceptions/response/ErrorResponseBodyProvider.java
Show resolved
Hide resolved
Co-authored-by: Jonas Konrad <[email protected]>
…response/ErrorResponseBodyProvider.java Co-authored-by: Jonas Konrad <[email protected]>
...rc/main/java/io/micronaut/http/server/exceptions/response/HtmlErrorResponseBodyProvider.java
Outdated
Show resolved
Hide resolved
@@ -96,7 +95,6 @@ public void close() { | |||
* | |||
* @param args The arguments passed to main | |||
* @param supplier The function that executes this function | |||
* @throws IOException If an error occurs |
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.
Otherwise, Javadoc complains of a throw javadoc for an exception not being thrown.
Quality Gate passedIssues Measures |
This PR changes the error processor to respond to a nice HTML error page if the request accepts an HTML Response. Similar to the error pages of Kamal proxy. The background blue, is the same as the blue used in the Micronaut Website.
This pull request also adds a
HtmlSanitizer
API, which Micronaut Security will further enhance.I generated a SVG per status code, using a Shortcuts + Pixelmator script.For JSON responses, the application will respond
vnd.error
as it currently does.It also allows multiple body assertions in TCK.
Currently, a not found page is displayed as:
With the changes in this pull-request, it is displayed as:
A Bad request (e.g., after a validation) currently is displayed as:
With the changes in this pull-request, it is displayed as: