| | |
| | | @ExceptionHandler(SQLException.class) |
| | | public Result<?> handlerSQLException(SQLException e) { |
| | | log.error(e.getMessage().toLowerCase(), e); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("数据操作失败!请联系管理员"); |
| | | } |
| | | |
| | |
| | | log.error(String.valueOf(e)); |
| | | String message = e.getCause().getMessage(); |
| | | String[] split = message.split("'"); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("重复添加:【" + split[1] + "】操作失败!"); |
| | | } |
| | | |
| | | @ExceptionHandler |
| | | public Result<?> NullPointerException(NullPointerException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("部分参数为空,请检查!"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(RuntimeException.class) |
| | | public Result<?> runtimeExceptionHandler(RuntimeException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("运行时异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(ClassCastException.class) |
| | | public Result<?> classCastExceptionHandler(ClassCastException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("类型转换异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(FileNotFoundException.class) |
| | | public Result<?> FileNotFoundException(FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("文件未找到异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(NumberFormatException.class) |
| | | public Result<?> NumberFormatException(NumberFormatException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("数字格式异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(SecurityException.class) |
| | | public Result<?> SecurityException(SecurityException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("安全异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(TypeNotPresentException.class) |
| | | public Result<?> TypeNotPresentException(TypeNotPresentException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("类型不存在异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(IOException.class) |
| | | public Result<?> iOExceptionHandler(IOException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("IO异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(NoSuchMethodException.class) |
| | | public Result<?> noSuchMethodExceptionHandler(NoSuchMethodException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("未知方法异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(IndexOutOfBoundsException.class) |
| | | public Result<?> indexOutOfBoundsExceptionHandler(IndexOutOfBoundsException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("数组越界异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(BadSqlGrammarException.class) |
| | | public Result<?> BadSqlGrammarException(BadSqlGrammarException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("sql语法错误异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler(NoSuchBeanDefinitionException.class) |
| | | public Result<?> NoSuchBeanDefinitionException(NoSuchBeanDefinitionException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("无法注入bean"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler({HttpMessageNotReadableException.class}) |
| | | public Result<?> requestNotReadable(HttpMessageNotReadableException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("Http消息不可读"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler({TypeMismatchException.class}) |
| | | public Result<?> requestTypeMismatch(TypeMismatchException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("服务器异常"); |
| | | } |
| | | |
| | | /** |
| | | * 500错误 |
| | | * 201错误 |
| | | */ |
| | | @ExceptionHandler({ConversionNotSupportedException.class, HttpMessageNotWritableException.class}) |
| | | public Result<?> server500(RuntimeException e) { |
| | | public Result<?> server201(RuntimeException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("服务器异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler({StackOverflowError.class}) |
| | | public Result<?> requestStackOverflow(StackOverflowError e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("栈溢出异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler({ArithmeticException.class}) |
| | | public Result<?> arithmeticException(ArithmeticException e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("除数不能为0异常"); |
| | | } |
| | | |
| | |
| | | @ExceptionHandler({Exception.class}) |
| | | public Result<?> exception(Exception e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(500); |
| | | response.setStatus(201); |
| | | return Result.fail("网络连接失败,请退出后再试"); |
| | | } |
| | | } |