Quarkus RestEasy ws.rs Resource, CompletionStage exception handling

纵然是瞬间 提交于 2019-12-24 18:41:32

问题


If I defined my rest-easy Resource this this way:

@GET
@Path("/stuff")
@Produces(MediaType.APPLICATION_JSON)
public Response getStuff() {
  final Single<Stuff> stuffSingle = stuffService.getStuffAsync();
   return Response.ok().entity(stuffSingle.blockingGet()).build();
 }

And exception happens somewhere at getStuffAsync() method.

I could go with ExceptionMapper to delegate it to handle exceptions.

@Provider
public class MyExceptionMapper implements ExceptionMapper<Exception> { ..

And it works - it is possible to handle exception and pass it to the user.

BUT if I go with Async Rest end-point:

@Path("/stuff")
@Produces(MediaType.APPLICATION_JSON)
public CompletionStage<Stuff> 

    stuffSingle = stuffService.getStufAsync();

    final CompletableFuture<Stuff> stuffSignle = new CompletableFuture<>();
    stuffSignle.subscribe(future::complete);

    return future

}

In case if exception, the endpoint would hang forever. No response would be propagated to the user. No MyExceptionMapper involvement.

Q: What is the way to handle it with CompletionStage in rest easy in Quarkus

来源:https://stackoverflow.com/questions/59257978/quarkus-resteasy-ws-rs-resource-completionstage-exception-handling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!