0
私のHystrix/Feign
は、他のWebサービスを呼び出します。Hystrix - ExceptionMapperの登録方法
これらのWebサービスからエラーコード/メッセージを伝播したいと思います。
ErrorDecoder
を実装しました。これは、返された例外を正しくデコードして再スローします。
残念ながら、これらの例外はHystrixRuntimeException
と、JSON
で返されます(一般的なエラーメッセージ、常に500 httpステータス)。
ExceptionMapper
が必要
ほとんどの場合、私はこのようなものを作成しました:
@Provider
public class GlobalExceptionHandler implements
ExceptionMapper<Throwable> {
@Override
public Response toResponse(Throwable e) {
System.out.println("ABCD 1");
if(e instanceof HystrixRuntimeException){
System.out.println("ABCD 2");
if(e.getCause() != null && 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();
}
}
残念ながら、このコードは、撮像されていない、私のアプリケーションでは(デバッグ文がログに表示されません)。
私は自分のアプリケーションにどのように登録できますか?