I'm usng GWTP rest dispath with ResourceDelegate and I want to catch all exceptions in client REST requests. My REST backend return:
- 401 or 403 status codes if no authorization/forbidden
- 500 for other errors
So, I have added common handler to RestDispatchAsyncModule:
new RestDispatchAsyncModule.Builder().exceptionHandler(MyRestExceptionHandler.class);
MyRestExceptionHandler.java:
public class MyRestExceptionHandler implements ExceptionHandler {
@Override
public Status onFailure(Throwable e) {
if (e instanceof ActionException){
ActionException a = (ActionException)e;
// How to get HTTP status code and response body here?
}
return null;
}
}
I found that all REST exception are instances of ActionException class. How can I get HTTP status code and http response body inside MyRestExceptionHandler?
The solution is to use RestDispatchHooks instead of ExceptionHandler.
AppRestDispatchHooks.java:
Installing module: