Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iandmyhand/5eac372fb2c6d1f6054d to your computer and use it in GitHub Desktop.
Save iandmyhand/5eac372fb2c6d1f6054d to your computer and use it in GitHub Desktop.
Handle error for RereadableRequestWrapper
@RequestMapping("/error")
@Controller
public class ErrorController {
@RequestMapping("/pageNotFound")
@ResponseBody
public Response pageNotFound() {
return new ErrorResponse(ErrorCode.NOT_FOUND_API.getCode(), ErrorCode.NOT_FOUND_API.getMessage());
}
@RequestMapping("/servletException")
@ResponseBody
public Response defaultServletExceptionResponse(HttpServletRequest request, HttpServletResponse response) {
ErrorResponse errorResponse = null;
try {
errorResponse = (ErrorResponse)request.getAttribute("errorResponse");
} catch (Exception e) {
}
if (errorResponse != null) {
return errorResponse;
} else {
return new ErrorResponse(ErrorCode.UNKNOWN.getCode(), ErrorCode.UNKNOWN.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment