mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-31 17:13:41 +00:00
添加异常mapping
This commit is contained in:
@@ -29,6 +29,10 @@ public enum ErrorCode {
|
||||
* 描述 : 方法不允许
|
||||
*/
|
||||
METHOD_NOT_ALLOWED("method not allowed"),
|
||||
/**
|
||||
* 描述 : Http媒体类型不可接受
|
||||
*/
|
||||
HTTP_MEDIA_TYPE_NOT_ACCEPTABLE("Http Media Type Not Acceptable"),
|
||||
/**
|
||||
* 描述 : 资源不存在
|
||||
*/
|
||||
|
||||
+15
@@ -13,6 +13,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.HttpMediaTypeNotAcceptableException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
@@ -138,6 +139,20 @@ public class ExceptionMapping {
|
||||
return new RestResponse<>(ErrorCode.METHOD_NOT_ALLOWED, buildError(exception));
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 捕获HttpMediaTypeNotAcceptableException异常(Http媒体类型不可接受)
|
||||
*
|
||||
* @param exception 异常
|
||||
* @return 错误信息
|
||||
*/
|
||||
@ExceptionHandler(value = HttpMediaTypeNotAcceptableException.class)
|
||||
@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
|
||||
@ResponseBody
|
||||
public RestResponse<String> httpMediaTypeNotAcceptableException(
|
||||
HttpMediaTypeNotAcceptableException exception) {
|
||||
return new RestResponse<>(ErrorCode.HTTP_MEDIA_TYPE_NOT_ACCEPTABLE, buildError(exception));
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 捕获SystemException异常(系统检查型异常)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user