title: How to manage exceptions thrown in filters in Spring?
body: <p>I want to use generic way to manage 5xx error codes, let's say specifically the case when the db is down across my whole spring application. I want a pretty error json instead of a stack trace. </p>
  
  <p>For the controllers I have a <code>@ControllerAdvice</code> class for the different exceptions and this is also catching the case that the db is stopping in the middle of the request. But this is not all. I also happen to have a custom <code>CorsFilter</code> extending <code>OncePerRequestFilter</code> and there when i call <code>doFilter</code> i get the <code>CannotGetJdbcConnectionException</code> and it will not be managed by the <code>@ControllerAdvice</code>. I read several things online that only made me more confused. </p>
  
  <p>So I have a lot of questions:</p>
  
  <ul>
  <li>Do i need to implement a custom filter? I found the <code>ExceptionTranslationFilter</code> but this only handles <code>AuthenticationException</code> or <code>AccessDeniedException</code>. </li>
  <li>I thought of implementing my own <code>HandlerExceptionResolver</code>, but this made me doubt, I don't have any custom exception to manage, there must be a more obvious way than this. I also tried to add a try/catch and call an implementation of the <code>HandlerExceptionResolver</code> (should be good enough, my exception is nothing special) but this is not returning anything in the response, i get a status 200 and an empty body. </li>
  </ul>
  
  <p>Is there any good way to deal with this? Thanks</p>