-
Notifications
You must be signed in to change notification settings - Fork 8
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
Catch application errors to display standardized error page #122
Conversation
poke @groldan I think DT's request is similar to what is intended here. |
9258c85
to
23ebff5
Compare
return chain.filter(exchange).then(Mono.fromRunnable(() -> { | ||
if (exchange.getResponse().getStatusCode().is4xxClientError() || exchange.getResponse().getStatusCode().is5xxServerError()) { | ||
// log error ? | ||
throw new RuntimeException("SERVICE ERROR"); |
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.
It'd be ideal if we throw an exception that preserves the status code. I can't remember how they're called right now though
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.
org.springframework.web.server.ResponseStatusException
that's 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.
Also, as discussed in our meeting, it'd be great if this filter could be enabled through a config property, being disabled by default
either way, whether it's enabled or disabled by default, just make sure to add an entry in the security docs |
23ebff5
to
b857189
Compare
b857189
to
d165641
Compare
…teway returns an error. `GatewayFilterFactory` providing a `GatewayFilter` that throws a `ResponseStatusException` with the proxied response status code if the target responded with a `400` or `500` status code. Usage: to enable it globally, add this to application.yaml : ``` spring: cloud: gateway: default-filters: - ApplicationError ``` To enable it only on some routes, add this to concerned routes in `routes.yaml`: ``` filters: - name: ApplicationError ```
0d97ed5
to
e7d266a
Compare
We wanted to show a standardized error page when an application behind the gateway returns an HTTP 4xx or 5xx error, instead of an application specific error page.
It uses error pages templates embedded in gateway or overriden in
gateway/template/error
directory of datadir.To enable it globally, add this to
gateway/application.yaml
of datadir :To enable it only on some routes, add this to concerned routes in
gateway/routes.yaml
of datadir :A side effect that can be discussed is that it prints a stack trace in gateway log as implementation throws an exception. Some things can be done differently, like using a more specific exception class, or catch it in a
AbstractErrorWebExceptionHandler
subclass to maybe avoid to print it in log, or do not throw an exception but replace content of response by content of500.html
template. Suggestions are welcome.Example of log with printed stacktrace :