com.centurylink.mdw.boot.ErrorController Maven / Gradle / Ivy
package com.centurylink.mdw.boot;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
@Controller
public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController {
@Override
public String getErrorPath() {
return "/error";
}
@SuppressWarnings("squid:S3752")
@RequestMapping("/error")
public String handleError(HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
Integer statusCode = Integer.valueOf(status.toString());
if (statusCode == HttpStatus.NOT_FOUND.value()) {
return "404";
}
else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
return "500";
}
}
return "error";
}
}