code formatted.

This commit is contained in:
Ankush Sharma 2016-10-31 12:11:37 +05:30
parent e8dc2be8c1
commit d100f84ea9

View File

@ -9,44 +9,43 @@ import org.springframework.web.servlet.ModelAndView;
@Controller @Controller
public class ErrorController { public class ErrorController {
@RequestMapping(value = "500Error" , method = RequestMethod.GET) @RequestMapping(value = "500Error", method = RequestMethod.GET)
public void throwRuntimeException(){ public void throwRuntimeException() {
throw new NullPointerException("Throwing a null pointer exception"); throw new NullPointerException("Throwing a null pointer exception");
} }
@RequestMapping(value = "errors" , method = RequestMethod.GET) @RequestMapping(value = "errors", method = RequestMethod.GET)
public ModelAndView renderErrorPages(HttpServletRequest httpRequest){ public ModelAndView renderErrorPages(HttpServletRequest httpRequest) {
ModelAndView errorPage = new ModelAndView("errorPage"); ModelAndView errorPage = new ModelAndView("errorPage");
String errorMsg = ""; String errorMsg = "";
int httpErrorCode = getErrorCode(httpRequest); int httpErrorCode = getErrorCode(httpRequest);
switch( httpErrorCode ){ switch (httpErrorCode) {
case 400:{ case 400: {
errorMsg = "Http Error Code : 400 . Bad Request"; errorMsg = "Http Error Code : 400 . Bad Request";
break; break;
} }
case 401:{ case 401: {
errorMsg = "Http Error Code : 401. Unauthorized"; errorMsg = "Http Error Code : 401. Unauthorized";
break; break;
} }
case 404:{ case 404: {
errorMsg = "Http Error Code : 404. Resource not found"; errorMsg = "Http Error Code : 404. Resource not found";
break; break;
} }
//Handle other 4xx error codes. // Handle other 4xx error codes.
case 500:{ case 500: {
errorMsg = "Http Error Code : 500. Internal Server Error"; errorMsg = "Http Error Code : 500. Internal Server Error";
break; break;
} }
//Handle other 5xx error codes. // Handle other 5xx error codes.
} }
errorPage.addObject("errorMsg", errorMsg); errorPage.addObject("errorMsg", errorMsg);
return errorPage; return errorPage;
} }
private int getErrorCode(HttpServletRequest httpRequest){ private int getErrorCode(HttpServletRequest httpRequest) {
return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code"); return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code");
} }
} }