异常统一处理

This commit is contained in:
none
2023-02-07 17:47:52 +08:00
parent ebd77f97d4
commit c2aff11b22
4 changed files with 61 additions and 11 deletions

View File

@@ -0,0 +1,22 @@
package xyz.playedu.api.controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import xyz.playedu.api.exception.ServiceException;
import xyz.playedu.api.types.JsonResponse;
@RestControllerAdvice
public class ExceptionController {
@ExceptionHandler(Exception.class)
public JsonResponse<String> exceptionHandler(Exception e) {
return JsonResponse.error("系统错误", 500);
}
@ExceptionHandler(ServiceException.class)
public JsonResponse<String> serviceExceptionHandler(ServiceException e) {
return JsonResponse.error(e.getMessage(), 1);
}
}