فهرست منبع

全局异常捕获添加邮件相关异常

ControlDream 1 سال پیش
والد
کامیت
f5fac181d2
1فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 11 1
      src/main/java/com/fjhx/email/config/exception/UnifiedExceptionHandler.java

+ 11 - 1
src/main/java/com/fjhx/email/config/exception/UnifiedExceptionHandler.java

@@ -9,6 +9,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 
+import javax.mail.MessagingException;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Objects;
 
@@ -64,10 +65,19 @@ public class UnifiedExceptionHandler {
     /**
      * 其他未知异常
      */
+    @ExceptionHandler(value = MessagingException.class)
+    public R handleException(MessagingException e) {
+        log.error(request.getRequestURI(), e);
+        return R.error(HttpStatus.HTTP_INTERNAL_ERROR, "邮件相关异常,异常信息:" + e.getMessage());
+    }
+
+    /**
+     * 其他未知异常
+     */
     @ExceptionHandler(value = Exception.class)
     public R handleException(Exception e) {
         log.error(request.getRequestURI(), e);
-        return R.error(HttpStatus.HTTP_INTERNAL_ERROR, "系统出现未知异常,请联系管理员");
+        return R.error(HttpStatus.HTTP_INTERNAL_ERROR, "邮件服务出现未知异常,请联系管理员");
     }
 
 }