zzw
昨天 1332cc511936d7dbe804921bc733c83d5e4d1400
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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, HttpServletRequest request) {
        errorLogRecorder.record(exception, request);
        exception.printStackTrace();
        return Result.error(exception.getMessage() == null ? "系统异常" : exception.getMessage());
    }
}