From 836a4c783eb77ed163d73e59a4ccc84a73aff70b Mon Sep 17 00:00:00 2001 From: wangkang Date: Fri, 19 May 2017 10:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../egridcloud/udf/core/exception/ErrorCode.java | 4 ++++ .../core/exception/handle/ExceptionMapping.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java index db128b4..06d1844 100644 --- a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java @@ -29,6 +29,10 @@ public enum ErrorCode { * 描述 : 方法不允许 */ METHOD_NOT_ALLOWED("method not allowed"), + /** + * 描述 : Http媒体类型不可接受 + */ + HTTP_MEDIA_TYPE_NOT_ACCEPTABLE("Http Media Type Not Acceptable"), /** * 描述 : 资源不存在 */ diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java index e570a42..0c4dab0 100644 --- a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java @@ -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 httpMediaTypeNotAcceptableException( + HttpMediaTypeNotAcceptableException exception) { + return new RestResponse<>(ErrorCode.HTTP_MEDIA_TYPE_NOT_ACCEPTABLE, buildError(exception)); + } + /** * 描述 : 捕获SystemException异常(系统检查型异常) *