-
Notifications
You must be signed in to change notification settings - Fork 5
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
adding customized error pages with a specific api for error handling #107
adding customized error pages with a specific api for error handling #107
Conversation
@GetMapping(path = "/error/{code}") | ||
public String handleError(@PathVariable String code) { | ||
return "error/" + code; | ||
} | ||
|
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.
is this necessary ? Relying on the doc provided by @edevosc2c (https://github.com/georchestra/georchestra-gateway/blob/main/docs/custom-error-pages.adoc), as long as we have a template for each http error code under templates/error/xyz.html, it should work.
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.
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.
yes, it is related to "traefik.http.middlewares.static-errors-middleware.errors.query=/error/{status}"
But @pmauduit , it did work for me after just adding files under emplates/error (only 404 page worked!).
You can just check locally if you want.
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.
Just as update, we need to set traefik conf as follows to make it works :
- "traefik.http.middlewares.static-errors-middleware.errors.status=400-599"
- "traefik.http.middlewares.static-errors-middleware.errors.service=gateway"
- "traefik.http.middlewares.static-errors-middleware.errors.query=/error/{status}"
Here, we are saying that error will be handled by gateway and we redirect it to path /error/{status}.
after that we add a specific api for this path as show on the top.
Also traefik.http.routers.gateway.rule have to change to allow gateway to handle all request without restriction.
Check
https://github.com/georchestra/docker/pull/275/files#diff-2286cdeca85adb587a9640aa34352ba7c2fb6e49c0129dab05892ff67d0d4c58R78
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.
Then, as far as I understand it, it is specific to the fact that the docker composition is making use of traefik ? Then we should consider dropping it, and keep the gateway agnostic to whatever is used as a proxy before 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.
Good idea for me.
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.
OK, but how to handle errors for specific projects in such a case ?
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.
For me static-errors-middleware
in traefik is not needed anymore with the gateway because it's the gateway itself that will send the error pages.
b0517dd
to
80ae913
Compare
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.
LGTM on a fuctionnal way. Thanks @marwanehcine !
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.
If we now include the error pages directly into the gateway code, can we still override them through the datadir like in MEL: https://github.com/camptocamp/georchestra-mel-configuration/tree/k8s-master-dev/gateway/templates/error?
80ae913
to
614c288
Compare
Yes, just we need to set correct path in prop file. Thanks |
tested then replied, Thanks |
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 globally good to me even if I miss some context, just one remark though.
gateway/src/main/java/org/georchestra/gateway/security/GatewaySecurityConfiguration.java
Outdated
Show resolved
Hide resolved
7a859ec
to
126302e
Compare
adding customized error pages with a specific api for error handling (404, 403, 500, 501, 503)
I have added a new CustomAccessDeniedHandler class to throw an exception when 403 is returned.
Exception should be throw to be handled later by CustomErrorAttributes.java. (set error status and be redirected to correct html error page)