From b9a360339c2b3ce2e0a62b5e6f44cb9db080d913 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 14 Jul 2023 18:17:23 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=BB=9F=E4=B8=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/config/BaseExceptionHandler.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rymcu/forest/config/BaseExceptionHandler.java b/src/main/java/com/rymcu/forest/config/BaseExceptionHandler.java index 1a07fac..bedebd2 100644 --- a/src/main/java/com/rymcu/forest/config/BaseExceptionHandler.java +++ b/src/main/java/com/rymcu/forest/config/BaseExceptionHandler.java @@ -1,6 +1,6 @@ package com.rymcu.forest.config; -import com.alibaba.fastjson.support.spring.FastJsonJsonView; +import com.alibaba.fastjson.support.spring.annotation.FastJsonView; import com.rymcu.forest.core.exception.BusinessException; import com.rymcu.forest.core.exception.ServiceException; import com.rymcu.forest.core.exception.TransactionException; @@ -47,7 +47,7 @@ public class BaseExceptionHandler { result = new GlobalResult<>(ResultCode.UNAUTHORIZED); logger.info("用户无权限"); } else if (ex instanceof UnknownAccountException) { - // 账号或密码错误 + // 未知账号 result = new GlobalResult<>(ResultCode.UNKNOWN_ACCOUNT); logger.info(ex.getMessage()); } else if (ex instanceof AccountException) { @@ -91,7 +91,7 @@ public class BaseExceptionHandler { return result; } else { ModelAndView mv = new ModelAndView(); - FastJsonJsonView view = new FastJsonJsonView(); + FastJsonView view = new FastJsonView(); Map attributes = new HashMap(2); if (ex instanceof UnauthenticatedException) { attributes.put("code", ResultCode.UNAUTHENTICATED.getCode()); @@ -99,6 +99,16 @@ public class BaseExceptionHandler { } else if (ex instanceof UnauthorizedException) { attributes.put("code", ResultCode.UNAUTHORIZED.getCode()); attributes.put("message", ResultCode.UNAUTHORIZED.getMessage()); + } else if (ex instanceof UnknownAccountException) { + // 未知账号 + attributes.put("code", ResultCode.UNKNOWN_ACCOUNT.getCode()); + attributes.put("message", ex.getMessage()); + logger.info(ex.getMessage()); + } else if (ex instanceof AccountException) { + // 账号或密码错误 + attributes.put("code", ResultCode.INCORRECT_ACCOUNT_OR_PASSWORD.getCode()); + attributes.put("message", ex.getMessage()); + logger.info(ex.getMessage()); } else if (ex instanceof ServiceException) { //业务失败的异常,如“账号或密码错误” attributes.put("code", ((ServiceException) ex).getCode());