瀏覽代碼

优化第三方服务异常处理逻辑

woody 1 年之前
父節點
當前提交
dabe516ac0

+ 1 - 1
framework-email/src/main/java/com/chelvc/framework/email/DefaultEmailHandler.java

@@ -99,7 +99,7 @@ public class DefaultEmailHandler implements EmailHandler {
             transport.connect();
             transport.sendMessage(message, message.getAllRecipients());
         } catch (Exception e) {
-            log.warn("Email send failed: {}", e.getMessage(), e);
+            log.warn("Email send failed: {}", e.getMessage());
             return false;
         } finally {
             if (transport != null) {

+ 9 - 9
framework-jpush/src/main/java/com/chelvc/framework/jpush/DefaultJPushHandler.java

@@ -190,7 +190,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             message = this.restTemplate.exchange(url, HttpMethod.GET, entity, ChatMessage.class).getBody();
         } catch (Exception e) {
-            log.warn("JPush get chat message failed: {}", e.getMessage(), e);
+            log.warn("JPush get chat message failed: {}", e.getMessage());
             return null;
         }
         if (debug) {
@@ -220,7 +220,7 @@ public class DefaultJPushHandler implements JPushHandler {
                     TOKEN2MOBILE_URL, HttpMethod.POST, entity, JPushMobile.class
             ).getBody();
         } catch (Exception e) {
-            log.warn("JPush get mobile failed: {}", e.getMessage(), e);
+            log.warn("JPush get mobile failed: {}", e.getMessage());
             return null;
         }
         if (debug) {
@@ -259,7 +259,7 @@ public class DefaultJPushHandler implements JPushHandler {
                     && ((code = ((APIRequestException) e).getErrorCode()) == 1011 || code == 899001)) {
                 return true;
             }
-            log.warn("JPush register failed: {}", e.getMessage(), e);
+            log.warn("JPush register failed: {}", e.getMessage());
             return false;
         }
         if (debug) {
@@ -287,7 +287,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             result = this.getPushClient().sendPush(payload);
         } catch (Exception e) {
-            log.warn("JPush push failed: {}", e.getMessage(), e);
+            log.warn("JPush push failed: {}", e.getMessage());
             return 0;
         }
         if (debug) {
@@ -372,7 +372,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             result = this.getPushClient().batchSendPushByAlias(payloads);
         } catch (Exception e) {
-            log.warn("JPush push failed: {}", e.getMessage(), e);
+            log.warn("JPush push failed: {}", e.getMessage());
             return null;
         }
         if (debug) {
@@ -399,7 +399,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             result = this.getPushClient().getReceivedsDetail(ids);
         } catch (Exception e) {
-            log.warn("JPush get deliveries failed: {}", e.getMessage(), e);
+            log.warn("JPush get deliveries failed: {}", e.getMessage());
             return Collections.emptyList();
         }
         if (debug) {
@@ -436,7 +436,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             user = this.getMessageClient().getUserInfo(username);
         } catch (Exception e) {
-            log.warn("JPush get user info failed: {}", e.getMessage(), e);
+            log.warn("JPush get user info failed: {}", e.getMessage());
             return null;
         }
         if (debug) {
@@ -455,7 +455,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             state = this.getMessageClient().getUserState(username);
         } catch (Exception e) {
-            log.warn("JPush get user state failed: {}", e.getMessage(), e);
+            log.warn("JPush get user state failed: {}", e.getMessage());
             return null;
         }
         if (debug) {
@@ -477,7 +477,7 @@ public class DefaultJPushHandler implements JPushHandler {
         try {
             states = this.getMessageClient().getUsersState(usernames);
         } catch (Exception e) {
-            log.warn("JPush get user state failed: {}", e.getMessage(), e);
+            log.warn("JPush get user state failed: {}", e.getMessage());
             return new UserStateListResult[0];
         }
         if (debug) {

+ 1 - 1
framework-location/src/main/java/com/chelvc/framework/location/support/JuheMobileHandler.java

@@ -56,7 +56,7 @@ public class JuheMobileHandler implements MobileHandler {
         try {
             response = this.restTemplate.getForObject(url, JuheLocationResponse.class);
         } catch (Exception e) {
-            log.warn("Juhe locate failed: {}", e.getMessage(), e);
+            log.warn("Juhe locate failed: {}", e.getMessage());
             return null;
         }
         if (debug) {

+ 1 - 1
framework-location/src/main/java/com/chelvc/framework/location/support/TencentLocationHandler.java

@@ -60,7 +60,7 @@ public class TencentLocationHandler implements LocationHandler {
         try {
             response = this.restTemplate.getForObject(url, TencentLocationResponse.class);
         } catch (Exception e) {
-            log.warn("Tencent locate failed: {}", e.getMessage(), e);
+            log.warn("Tencent locate failed: {}", e.getMessage());
             return null;
         }
         if (debug) {

+ 3 - 2
framework-security/src/main/java/com/chelvc/framework/security/interceptor/SecurityExceptionInterceptor.java

@@ -10,6 +10,7 @@ import org.springframework.core.Ordered;
 import org.springframework.core.annotation.Order;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.core.AuthenticationException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseStatus;
@@ -33,9 +34,9 @@ public class SecurityExceptionInterceptor {
      * @return 请求结果
      */
     @ResponseStatus(HttpStatus.UNAUTHORIZED)
-    @ExceptionHandler(AuthenticationException.class)
+    @ExceptionHandler(BadCredentialsException.class)
     public Result<?> exception(HttpServletRequest request, HttpServletResponse response,
-                               AuthenticationException exception) {
+                               BadCredentialsException exception) {
         log.warn(HttpUtils.getExceptionMessage(request, HttpStatus.UNAUTHORIZED, exception));
         HttpUtils.initializeUnifiedResponseHeader(response);
         return Result.build(HttpStatus.UNAUTHORIZED);

+ 1 - 1
framework-sms/src/main/java/com/chelvc/framework/sms/support/AliyunSmsHandler.java

@@ -51,7 +51,7 @@ public class AliyunSmsHandler implements TemplateSmsHandler {
         try {
             response = this.client.sendSms(request);
         } catch (Exception e) {
-            log.warn("Aliyun sms send failed: {}", e.getMessage(), e);
+            log.warn("Aliyun sms send failed: {}", e.getMessage());
             return false;
         }
         if (debug) {

+ 1 - 1
framework-sms/src/main/java/com/chelvc/framework/sms/support/TencentTemplateSmsHandler.java

@@ -41,7 +41,7 @@ public class TencentTemplateSmsHandler implements TemplateSmsHandler {
             result = this.sender.sendWithParam(this.properties.getRegion(), mobile, Integer.parseInt(template),
                     parameters, this.properties.getSignature(), null, null);
         } catch (Exception e) {
-            log.warn("Tencent sms send failed: {}", e.getMessage(), e);
+            log.warn("Tencent sms send failed: {}", e.getMessage());
             return false;
         }
         if (debug) {

+ 1 - 1
framework-wechat/src/main/java/com/chelvc/framework/wechat/DefaultWechatPublicHandler.java

@@ -253,7 +253,7 @@ public class DefaultWechatPublicHandler implements WechatPublicHandler {
                 ).getBody();
             }
         } catch (Exception e) {
-            log.warn("Wechat public push failed: {}", e.getMessage(), e);
+            log.warn("Wechat public push failed: {}", e.getMessage());
             return 0;
         }
         if (response != null && response.getErrcode() == 0) {