diff --git a/service-configuration/src/main/java/com/lanyuanxiaoyao/service/configuration/controller/GlobalErrorController.java b/service-configuration/src/main/java/com/lanyuanxiaoyao/service/configuration/controller/GlobalErrorController.java new file mode 100644 index 0000000..a4c76f3 --- /dev/null +++ b/service-configuration/src/main/java/com/lanyuanxiaoyao/service/configuration/controller/GlobalErrorController.java @@ -0,0 +1,23 @@ +package com.lanyuanxiaoyao.service.configuration.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * 处理错误信息 + * + * @author lanyuanxiaoyao + * @date 2024-01-02 + */ +@ControllerAdvice +public class GlobalErrorController { + @ResponseBody + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(Throwable.class) + public String errorHandler(Throwable throwable) { + return throwable.getMessage(); + } +}