mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +08:00
Changed print exception to print log with exception
This commit is contained in:
@@ -2,18 +2,27 @@ package com.cfive.pinnacle.handler;
|
||||
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class CustomExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ResponseResult exceptionHandler(Exception e) {
|
||||
e.printStackTrace();
|
||||
if (e instanceof DuplicateKeyException) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "无法添加重复数据", null);
|
||||
}
|
||||
if (e instanceof BadCredentialsException) {
|
||||
return ResponseResult.build(ResponseCode.LOGOUT_FAILED, e.getMessage(), null);
|
||||
}
|
||||
|
||||
log.debug(e.getMessage(), e);
|
||||
|
||||
return ResponseResult.fail(e.getClass().toString() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user