27 lines
1020 B
Java
27 lines
1020 B
Java
package com.linhelp.common.exception;
|
|
|
|
import com.linhelp.common.api.ApiResponse;
|
|
import org.springframework.validation.BindException;
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
@RestControllerAdvice
|
|
public class GlobalExceptionHandler {
|
|
|
|
@ExceptionHandler(BizException.class)
|
|
public ApiResponse<Void> handleBizException(BizException exception) {
|
|
return ApiResponse.fail(exception.getCode(), exception.getMessage());
|
|
}
|
|
|
|
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
|
|
public ApiResponse<Void> handleValidationException(Exception exception) {
|
|
return ApiResponse.fail(422, "请求参数不正确");
|
|
}
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
public ApiResponse<Void> handleException(Exception exception) {
|
|
return ApiResponse.fail(500, "系统繁忙,请稍后再试");
|
|
}
|
|
}
|