mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-29 19:53:40 +00:00
添加异常处理方法
This commit is contained in:
@@ -25,6 +25,10 @@ public enum ErrorCode {
|
||||
* 描述 : 参数校验错误
|
||||
*/
|
||||
PARAMETER_VALID_ERROR("parameter check error"),
|
||||
/**
|
||||
* 描述 : 方法不允许
|
||||
*/
|
||||
METHOD_NOT_ALLOWED("method not allowed"),
|
||||
/**
|
||||
* 描述 : 资源不存在
|
||||
*/
|
||||
|
||||
+21
@@ -14,6 +14,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -167,6 +168,26 @@ public class ExceptionMapping {
|
||||
return new RestResponse<>(returnCode, returnMessage, em);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 捕获httpRequestMethodNotSupportedException异常(方法不允许)
|
||||
*
|
||||
* @param httpRequestMethodNotSupportedException 异常
|
||||
* @return 错误信息
|
||||
*/
|
||||
@ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
|
||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||
@ResponseBody
|
||||
public RestResponse<ErrorMessage> httpRequestMethodNotSupportedException(
|
||||
HttpRequestMethodNotSupportedException httpRequestMethodNotSupportedException) {
|
||||
String returnCode = ErrorCode.METHOD_NOT_ALLOWED.name();
|
||||
String returnMessage = ErrorCode.METHOD_NOT_ALLOWED.value();
|
||||
ErrorMessage em = ExceptionMapping.buildErrorMessage(HttpStatus.METHOD_NOT_ALLOWED.value(),
|
||||
returnCode, returnMessage, applicationConfig.isOutputExceptionStackTrace(),
|
||||
httpRequestMethodNotSupportedException);
|
||||
LOGGER.error(em.getId(), httpRequestMethodNotSupportedException);
|
||||
return new RestResponse<>(returnCode, returnMessage, em);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 捕获SystemException异常(系统检查型异常)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user