Skip to content

Instantly share code, notes, and snippets.

@wbotelhos
Created March 13, 2012 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbotelhos/2031577 to your computer and use it in GitHub Desktop.
Save wbotelhos/2031577 to your computer and use it in GitHub Desktop.
Ajax Exception Interceptor
@Intercepts
public class AjaxExceptionInterceptor implements Interceptor {
private final HttpServletRequest request;
private final Result result;
public AjaxExceptionInterceptor(HttpServletRequest request, Result result) {
this.request = request;
this.result = result;
}
public boolean accepts(ResourceMethod method) {
return request.getHeader("accept").contains("application/json");
}
public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) {
try {
stack.next(method, resourceInstance);
} catch (Exception e) {
result.use(Results.http()).sendError(500, e.getCause().getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment