mirror of https://github.com/halo-dev/halo
pref: 添加错误码&修改过时方法 (#1089)
parent
d3953fe864
commit
868efecdce
|
@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
|
||||
import org.springframework.boot.web.error.ErrorAttributeOptions;
|
||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
@ -79,7 +80,9 @@ public class CommonController extends AbstractErrorController {
|
|||
|
||||
handleCustomException(request);
|
||||
|
||||
Map<String, Object> errorDetail = Collections.unmodifiableMap(getErrorAttributes(request, isIncludeStackTrace(request)));
|
||||
ErrorAttributeOptions options = getErrorAttributeOptions(request);
|
||||
|
||||
Map<String, Object> errorDetail = Collections.unmodifiableMap(getErrorAttributes(request, options));
|
||||
model.addAttribute("error", errorDetail);
|
||||
model.addAttribute("meta_keywords", optionService.getSeoKeywords());
|
||||
model.addAttribute("meta_description", optionService.getSeoDescription());
|
||||
|
@ -87,6 +90,7 @@ public class CommonController extends AbstractErrorController {
|
|||
|
||||
HttpStatus status = getStatus(request);
|
||||
|
||||
response.setStatus(status.value());
|
||||
if (status.equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
|
||||
return contentInternalError();
|
||||
} else if (status.equals(HttpStatus.NOT_FOUND)) {
|
||||
|
@ -209,4 +213,21 @@ public class CommonController extends AbstractErrorController {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ErrorAttributeOptions .
|
||||
*
|
||||
* @param request the source request
|
||||
* @return {@link ErrorAttributeOptions}
|
||||
*/
|
||||
private ErrorAttributeOptions getErrorAttributeOptions(HttpServletRequest request) {
|
||||
ErrorProperties.IncludeStacktrace include = errorProperties.getIncludeStacktrace();
|
||||
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) {
|
||||
return ErrorAttributeOptions.of(ErrorAttributeOptions.Include.STACK_TRACE);
|
||||
}
|
||||
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM && getTraceParameter(request)) {
|
||||
return ErrorAttributeOptions.of(ErrorAttributeOptions.Include.STACK_TRACE);
|
||||
}
|
||||
return ErrorAttributeOptions.defaults();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue