mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
240 stars 54 forks source link

Custom Exception Handling? #97

Closed kaihenkel closed 4 years ago

kaihenkel commented 4 years ago

I would like to use the default error handling from spring boot when throwing an from within an custom interceptor. This will display the spring-boot whitelabel error page, which I will be using. The main Problem is, that even though i throw an ResponseStatusException the response-status is allways 500.

I have created a small demo-project that demonstrates the problem here.

Anny Suggestions how I could handle this problem?

mkopylec commented 4 years ago

Hi, in your example you can change:

throw new ResponseStatusException(HttpStatus.I_AM_A_TEAPOT);

to

return new HttpResponse(HttpStatus.I_AM_A_TEAPOT);

If you want to redirect to some error page just return a response with FOUND status and header Location: /url/to/error/page

kaihenkel commented 4 years ago

hi, thank you for you're quick response! I will try that first thing when I am back at the office on Monday. I will comment my results here. best regards, Kai Henkel

kaihenkel commented 4 years ago

Hi Again,

As promised I reviewed you're solution this morning and it is actually not what i was looking for. In you're solution I am redirecting the customer to the error page.

I was looking for a solution that utilizes the spring-error handling with the customizable error-page.

I updated my example project to illustrate the problem further.

kaihenkel commented 4 years ago

Ok, so I implemented an custom-spring filter that throws the a ResponseStatusException. As it turns out, this also leads to an internal server error response, event though I set another status code within the exception. So, its not a problem with you're proxy but a spring one.

Therefore I am closing this issue. However, for everyone interested, if I find a working solution I will update my example project accordingly.

Thank you for you're help!

mkopylec commented 4 years ago

Hi. Have you tried to change Charon's filter order? See here

kaihenkel commented 4 years ago

Hi, Yes, I tried that, the problem is not within the charon-framework but that exceptions thrown within the filter/interceptors generally won't be handled by the spring-error eco system.

However, i have found a solution and updated my example with a working solution.

Thanks again for you're support.