You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.6 KiB
Java
64 lines
2.6 KiB
Java
package com.supervision.livedigitalavatarmanage.config;
|
|
|
|
import com.supervision.livedigitalavatarmanage.constant.ResultStatusEnum;
|
|
import com.supervision.livedigitalavatarmanage.dto.R;
|
|
import com.supervision.livedigitalavatarmanage.exception.BusinessException;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
|
|
|
/**
|
|
* 统一异常处理器配置
|
|
*
|
|
* @author wb
|
|
* @date 2022/3/10 13:24
|
|
*/
|
|
@Slf4j
|
|
@Configuration
|
|
@RestControllerAdvice(annotations = RestController.class, basePackages = {"com.supervision.ai.service.**.controller"})
|
|
public class ExceptionHandlerConfig {
|
|
|
|
/**
|
|
* 添加手动校验参数的异常处理
|
|
*
|
|
* @param exception 参数验证异常
|
|
* @return 通用返回值
|
|
*/
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
public R<?> manualValidationExceptionResponse(IllegalArgumentException exception) {
|
|
log.error("=========手动校验参数异常=========>>>");
|
|
log.error(exception.getMessage(), exception);
|
|
log.error("<<<=========手动校验参数异常=========");
|
|
return R.fail(ResultStatusEnum.ILLEGAL_ARGUMENT.getCode(), exception.getMessage());
|
|
}
|
|
|
|
@ExceptionHandler(BusinessException.class)
|
|
public R<?> businessExceptionResponse(BusinessException exception) {
|
|
log.error("=========运行异常=========>>>");
|
|
log.error(exception.getMessage(), exception);
|
|
log.error("<<<=========运行异常=========");
|
|
|
|
return R.fail(511, exception.getMessage());
|
|
}
|
|
|
|
@ExceptionHandler(RuntimeException.class)
|
|
public R<?> manualValidationExceptionResponse(RuntimeException exception) {
|
|
log.error("=========运行异常=========>>>");
|
|
log.error(exception.getMessage(), exception);
|
|
log.error("<<<=========运行异常=========");
|
|
|
|
return R.fail(ResultStatusEnum.RUNTIME_EXCEPTION.getCode(), exception.getMessage());
|
|
}
|
|
|
|
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
|
public R<?> handleMaxSizeException(MaxUploadSizeExceededException exception) {
|
|
log.error("=========文件大小超出限制异常=========>>>");
|
|
log.error(exception.getMessage(), exception);
|
|
log.error("<<<=========文件大小超出限制异常=========");
|
|
return R.fail(ResultStatusEnum.EXCEED_FILE_SIZE.getCode(), exception.getMessage());
|
|
}
|
|
}
|