| | |
| | | package com.oying.exception.handler; |
| | | |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.exception.EntityExistException; |
| | | import com.oying.exception.EntityNotFoundException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.utils.DuplicateKeyExceptionUtil; |
| | | import com.oying.utils.ThrowableUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | | import org.springframework.validation.FieldError; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 处理 DuplicateKeyException |
| | | */ |
| | | @ExceptionHandler(value = DuplicateKeyException.class) |
| | | public ResponseEntity<ApiError> handleDuplicateKeyException(DuplicateKeyException e) { |
| | | // 打印堆栈信息 |
| | | log.error(ThrowableUtil.getStackTrace(e)); |
| | | return buildResponseEntity(ApiError.error(BAD_REQUEST.value(), DuplicateKeyExceptionUtil.getDisplayMessage(e))); |
| | | } |
| | | |
| | | /** |
| | | * 统一返回 |
| | | */ |
| | | private ResponseEntity<ApiError> buildResponseEntity(ApiError apiError) { |