38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package com.unisinsight.project.exception;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
@RestControllerAdvice
|
|
@Slf4j
|
|
public class GlobalExceptionHandler {
|
|
|
|
/**
|
|
* 处理业务异常
|
|
*/
|
|
@ExceptionHandler(BusinessException.class)
|
|
public Result<?> handleBusinessException(BusinessException e) {
|
|
log.error("业务异常:", e);
|
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, e.getMessage());
|
|
}
|
|
|
|
/**
|
|
* 处理参数校验异常
|
|
*/
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
public Result<?> handleIllegalArgumentException(IllegalArgumentException e) {
|
|
log.error("参数校验异常:", e);
|
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_400, e.getMessage());
|
|
}
|
|
|
|
/**
|
|
* 处理其他异常
|
|
*/
|
|
@ExceptionHandler(Exception.class)
|
|
public Result<?> handleException(Exception e) {
|
|
log.error("系统异常:", e);
|
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, e.getMessage());
|
|
}
|
|
}
|