This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enderbyendera-realtime-prot…/src/main/java/com/realtime/protection/configuration/exception/GlobalExceptionHandler.java
松岳 陈 06886de328 1. 增加jackson配置,缩减json数据长度
2. ExceptionHandler添加SaTokenException检查,用于校验登陆
3. ResponseResult添加invalid和unauthorized静态方法
4. Task模块添加单查询,多查询,更新路由
5. Template添加两个JsonProperty
6. Template模块添加query路由
7.
2024-01-03 22:53:02 +08:00

56 lines
2.1 KiB
Java

package com.realtime.protection.configuration.exception;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.SaTokenException;
import com.realtime.protection.configuration.response.ResponseResult;
import io.swagger.v3.oas.annotations.ExternalDocumentation;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.stream.Collectors;
@RestControllerAdvice
public class GlobalExceptionHandler {
@Order(3)
@ExceptionHandler(value = Exception.class)
public ResponseResult handleGlobalException(Exception e) {
return ResponseResult.error().setMessage(e.getMessage());
}
@Order(2)
@ExceptionHandler(value = NotLoginException.class)
public ResponseResult handleNotLoginException(NotLoginException e) {
return new ResponseResult(
401,
e.getMessage()
);
}
@Order(2)
@ExceptionHandler(value = PersistenceException.class)
public ResponseResult handleSQLException(PersistenceException e) {
return ResponseResult.invalid().setMessage(
"please check the integrity of the data. check if the json data exists in the database");
}
@Order(2)
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
return ResponseResult.invalid().setMessage(
e.getBindingResult().getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining())
);
}
@Order(2)
@ExceptionHandler(value = SaTokenException.class)
public ResponseResult handleSaTokenException(SaTokenException e) {
return ResponseResult.unAuthorized().setMessage(e.getMessage());
}
}