diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/config/GlobalExceptionHandler.java b/blade-service/logpm-report/src/main/java/com/logpm/report/config/GlobalExceptionHandler.java new file mode 100644 index 000000000..6f63dc054 --- /dev/null +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/config/GlobalExceptionHandler.java @@ -0,0 +1,25 @@ +package com.logpm.report.config; + +import com.alibaba.fastjson.JSONObject; +import org.springblade.common.exception.CustomerException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +/** + * @Author: zqb + * @Date: 2024/11/13 + */ +@ControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(CustomerException.class) + public ResponseEntity handleCustomException(CustomerException e) { + JSONObject js = new JSONObject(); + js.put("code", e.getCode()); + js.put("msg", e.getMessage()); + return new ResponseEntity<>(js, HttpStatus.BAD_REQUEST); + } + +}