xyc
3 天以前 53052625c7c520744a4ca061e204ec9594ca67f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.emergencyrepair.common;
 
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
 
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public Result<Void> handleBusiness(BusinessException exception) {
        return Result.error(exception.getMessage());
    }
 
    @ExceptionHandler(Exception.class)
    public Result<Void> handleOther(Exception exception) {
        exception.printStackTrace();
        return Result.error(exception.getMessage() == null ? "系统异常" : exception.getMessage());
    }
}