feat: add core schema and status enums
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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, "系统繁忙,请稍后再试");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user