| | |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
| | | import org.springframework.web.servlet.NoHandlerFoundException; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.ConstraintViolation; |
| | |
| | | } |
| | | if (ex instanceof AccessDeniedException) { |
| | | return accessDeniedExceptionHandler(request, (AccessDeniedException) ex); |
| | | } |
| | | if (ex instanceof DuplicateKeyException) { |
| | | return duplicateKeyExceptionHandler((DuplicateKeyException) ex); |
| | | } |
| | | return defaultExceptionHandler(request, ex); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 处理业务异常 SQLIntegrityConstraintViolationException |
| | | * |
| | | * 数据库存在重复数据 |
| | | */ |
| | | @ExceptionHandler(value = DuplicateKeyException.class) |
| | | public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) { |
| | | log.warn("[duplicateKeyExceptionHandler]", ex); |
| | | return CommonResult.error(DATA_REPETITION.getCode(), DATA_REPETITION.getMsg()); |
| | | } |
| | | |
| | | /** |
| | | * 处理业务异常 ServiceException |
| | | * |
| | | * 例如说,商品库存不足,用户手机号已存在。 |