I'm usng GWTP rest dispath with ResourceDelegate and I want to catch all exceptions in client REST requests. My REST backend return:
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?
答案 0 :(得分:0)
解决方案是使用RestDispatchHooks而不是ExceptionHandler。
<强> AppRestDispatchHooks.java:强>
public class AppRestDispatchHooks implements RestDispatchHooks {
@Override
public void onExecute(RestAction<?> action) {
}
@Override
public void onSuccess(RestAction<?> action, Response response, Object result) {
}
@Override
public void onFailure(RestAction<?> action, Response response, Throwable caught) {
GWT.log("Status code:"+ response.getStatusCode());
}
}
安装模块:
install(new RestDispatchAsyncModule.Builder()
.dispatchHooks(AppRestDispatchHooks.class)
.build())