title: Hystrix - how to register ExceptionMapper
body: <p>My <code>Hystrix/Feign</code> app makes calls to other web services.</p>
  
  <p>I would like to propagate error codes/messages from these web services.</p>
  
  <p>I implemented <code>ErrorDecoder</code>, which correctly decodes exceptions returned and rethrow them.</p>
  
  <p>Unfortunately these Exceptions are wrapped by <code>HystrixRuntimeException</code> and the <code>JSON</code> returned in not what I want (generic error message, always 500 http status).</p>
  
  <p>Most likely I need an <code>ExceptionMapper</code>, I created one like this:</p>
  
  <pre><code>@Provider
  public class GlobalExceptionHandler implements
      ExceptionMapper&lt;Throwable&gt; {
  
  @Override
  public Response toResponse(Throwable e) {
      System.out.println("ABCD 1");
      if(e instanceof HystrixRuntimeException){
          System.out.println("ABCD 2");
          if(e.getCause() != null &amp;&amp; e.getCause() instanceof HttpStatusCodeException)
          {
              System.out.println("ABCD 3");
              HttpStatusCodeException exc = (HttpStatusCodeException)e.getCause();
              return Response.status(exc.getStatusCode().value())
                      .entity(exc.getMessage())
                      .type(MediaType.APPLICATION_JSON).build();
          }
      }
      return Response.status(500).entity("Internal server error").build();
  }
  }
  </code></pre>
  
  <p>Unfortunately this code is not being picked-up by my application (debug statements are not visible in logs).</p>
  
  <p>How could I register it with my Application?</p>