Skip to content
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

Custom Exception Handling? #97

Closed
kaihenkel opened this issue Nov 8, 2019 · 6 comments
Closed

Custom Exception Handling? #97

kaihenkel opened this issue Nov 8, 2019 · 6 comments

Comments

@kaihenkel
Copy link

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
Copy link
Owner

mkopylec commented Nov 8, 2019

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
Copy link
Author

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
Copy link
Author

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.

  • /testerror - will throw the teapot exception
  • /testmessage - will redirect to the example error-page
  • /message - will throw the teapot exception from within a "normal" spring controller. This is the behavior i would like to have when throwing an exception from within an Interceptor.

kaihenkel added a commit to kaihenkel/charon-spring-boot-starter-exception-handling that referenced this issue Nov 11, 2019
kaihenkel added a commit to kaihenkel/charon-spring-boot-starter-exception-handling that referenced this issue Nov 11, 2019
@kaihenkel
Copy link
Author

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
Copy link
Owner

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

@kaihenkel
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants