From a64a0e3887b6e0950ce3a7f99d8038d7550cced1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 21 May 2019 15:33:35 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9Aproduct=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=A2=9E=E5=8A=A0=20metrics=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 58 ------------------- .../src/main/resources/application.yaml | 9 +++ 2 files changed, 9 insertions(+), 58 deletions(-) delete mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java deleted file mode 100644 index f49d1872b..000000000 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/exception/GlobalExceptionHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.common.framework.exception; - -import cn.iocoder.common.framework.constant.SysErrorCodeEnum; -import cn.iocoder.common.framework.vo.CommonResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.ConstraintViolationException; - -@ControllerAdvice -public class GlobalExceptionHandler { - - private Logger logger = LoggerFactory.getLogger(getClass()); - - // 逻辑异常 - @ResponseBody - @ExceptionHandler(value = ServiceException.class) - public CommonResult serviceExceptionHandler(HttpServletRequest req, ServiceException ex) { - logger.debug("[serviceExceptionHandler]", ex); - return CommonResult.error(ex.getCode(), ex.getMessage()); - } - - // Spring MVC 参数不正确 - @ResponseBody - @ExceptionHandler(value = MissingServletRequestParameterException.class) - public CommonResult missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException ex) { - logger.warn("[missingServletRequestParameterExceptionHandler]", ex); - return CommonResult.error(SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage() + ":" + ex.getMessage()); - } - - @ResponseBody - @ExceptionHandler(value = ConstraintViolationException.class) - public CommonResult constraintViolationExceptionHandler(HttpServletRequest req, ConstraintViolationException ex) { - logger.info("[constraintViolationExceptionHandler]", ex); - // TODO 芋艿,后续要想一个更好的方式。 - // 拼接详细报错 - StringBuilder detailMessage = new StringBuilder("\n\n详细错误如下:"); - ex.getConstraintViolations().forEach(constraintViolation -> detailMessage.append("\n").append(constraintViolation.getMessage())); - return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getMessage() - + detailMessage.toString()); - } - - @ResponseBody - @ExceptionHandler(value = Exception.class) - public CommonResult resultExceptionHandler(HttpServletRequest req, Exception e) { - logger.error("[resultExceptionHandler]", e); - // 返回 - return CommonResult.error(SysErrorCodeEnum.SYS_ERROR.getCode(), SysErrorCodeEnum.SYS_ERROR.getMessage()); - } - - // TODO 芋艿,应该还有其它的异常,需要进行翻译 - -} diff --git a/product/product-application/src/main/resources/application.yaml b/product/product-application/src/main/resources/application.yaml index e6c88ddad..759bb545a 100644 --- a/product/product-application/src/main/resources/application.yaml +++ b/product/product-application/src/main/resources/application.yaml @@ -18,3 +18,12 @@ server: swagger: enable: false + + +management: + endpoints: + web: + exposure: + include: health,info,env,metrics,prometheus + metrics: + enabled: true