From 4f99f59668c9160ca60958b7347944def26f2228 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期日, 27 四月 2025 10:58:53 +0800 Subject: [PATCH] 回退配置 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/GlExceptionHandler.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/GlExceptionHandler.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/GlExceptionHandler.java new file mode 100644 index 0000000..3f5d4a6 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/webUtil/GlExceptionHandler.java @@ -0,0 +1,44 @@ +package com.dy.common.webUtil; + +import io.swagger.v3.oas.annotations.Hidden; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 鍏ㄥ眬寮傚父澶勭悊锛屽鐞嗗湪Controller涓姏鍑虹殑寮傚父锛屽湪Controller涔嬪墠锛堝Fileter锛夊彂鐢熺殑閿欒鎴栧紓甯哥敱GlErrorCtrl澶勭悊 + * 姝ょ被鏄熀浜庢嫤鎴櫒鍜屽疄鐜版寚瀹氭帴鍙o紙GlExceptionHandler鍜孏lExceptionHandlerImpl锛� + * 鍙︿竴绉嶅疄鐜版柟寮忔槸鍩轰簬娉ㄨВ鍒囬潰瀹炵幇锛圙lExceptionAspect锛� + */ +//姝ょ被Tag娉ㄨВ涓嶈捣浣滅敤锛屽嵆涓嶄細鍦╯wagger-ui涓樉绀猴紝浣嗕細鍦ㄦ瘡涓猚ontroler鐨勬柟娉曡繑鍥炰俊鎭腑鏄剧ず銆� +//姣忎釜controller鐨勬柟娉曚笂閮芥樉绀烘湰寮傚父API鏄剧ず鍟板棪锛屾墍浠ヤ笉鍚敤鏈敞瑙� +@Hidden //鍦⊿pringDoc涓殣钘忔湰鎺ュ彛API +@Tag(name = "鍏ㄥ眬寮傚父澶勭悊", description = "澶勭悊鍦–ontroller涓姏鍑虹殑寮傚父锛屽湪Controller涔嬪墠锛堝Fileter锛夊彂鐢熺殑閿欒鎴栧紓甯哥敱GlErrorCtrl澶勭悊") +//鍦ㄦ瘡涓猚ontroler鐨勬柟娉曡繑鍥炰俊鎭腑鏄剧ず涓嬮潰閰嶇疆淇℃伅銆� +@ApiResponses(@ApiResponse( + responseCode = ResultCodeMsg.RsCode.EXCEPTION_CODE, + description = "鍙戠敓寮傚父", + content = {@Content(mediaType = "application/json", schema = @Schema(implementation = BaseResponse.class))} +)) +@ControllerAdvice +@ResponseBody +@Slf4j +public class GlExceptionHandler { + + @ExceptionHandler + public BaseResponse GlExceptionHandler(GlException e){ + log.error("鎹曡幏鍒癎lException锛歿}", e.getMsg(), e); + return BaseResponseUtils.buildException(e.getMsg()); + } + + public BaseResponse exceptionHandler(Throwable t) { + log.error("鎹曡幏鍒板紓甯革細{}",t.getMessage(),t); + return BaseResponseUtils.buildException("鍦–ontroller涓垨鍚庝骇鐢熷紓甯革細" + t.getMessage()); + } +} -- Gitblit v1.8.0