| | |
| | | package com.emergencyrepair.common; |
| | | |
| | | import com.emergencyrepair.system.log.ErrorLogRecorder; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | @RestControllerAdvice |
| | | @RequiredArgsConstructor |
| | | public class GlobalExceptionHandler { |
| | | private final ErrorLogRecorder errorLogRecorder; |
| | | |
| | | @ExceptionHandler(BusinessException.class) |
| | | public Result<Void> handleBusiness(BusinessException exception) { |
| | | return Result.error(exception.getMessage()); |
| | | } |
| | | |
| | | @ExceptionHandler(Exception.class) |
| | | public Result<Void> handleOther(Exception exception) { |
| | | public Result<Void> handleOther(Exception exception, HttpServletRequest request) { |
| | | errorLogRecorder.record(exception, request); |
| | | exception.printStackTrace(); |
| | | return Result.error(exception.getMessage() == null ? "系统异常" : exception.getMessage()); |
| | | } |