Browse Source

增加后台异常信息提示到页面的功能

hejq 7 years ago
parent
commit
325259b3ec

+ 1 - 1
src/main/java/com/uas/platform/b2bManage/service/impl/InviteServiceImpl.java

@@ -234,7 +234,7 @@ public class InviteServiceImpl extends BaseService implements InviteService {
         if (null == userBaseInfo.getUu()) {
             userList = userBaseInfoDao.findByName(userMessage.trim());
             if (userList.size() > 1) {
-                throw new MyException("[" + userMessage + "]存在多条用户信息,请更新邀请用户信息");
+                throw new MyException("[" + userMessage + "]存在多条用户信息,请更新邀请用户信息,请尝试采用UU号或电话输入");
             } else if (userList.size() == 1) {
                 userBaseInfo = userList.get(0);
             }

+ 36 - 0
src/main/java/com/uas/platform/b2bManage/web/GlobalExceptionHandler.java

@@ -0,0 +1,36 @@
+package com.uas.platform.b2bManage.web;
+
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * 定义异常返回,将后台抛出的异常信息返回到前台提示
+ *
+ * @author hejq
+ * @date 2018-08-02 22:21
+ */
+@ControllerAdvice
+@Component
+public class GlobalExceptionHandler {
+
+    /**
+     * 监控异常
+     *
+     * @param e 异常
+     * @return
+     */
+    @ResponseBody
+    @ExceptionHandler(value = RuntimeException.class)
+    public ResponseEntity<String> defaultErrorHandler(Exception e) throws UnsupportedEncodingException {
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/text; charset=utf-8");
+        return new ResponseEntity(e.getMessage(), headers, HttpStatus.INTERNAL_SERVER_ERROR);
+    }
+}

+ 1 - 1
src/main/webapp/resources/js/account/resetPassword.js

@@ -36,7 +36,7 @@ function resetPassWord() {
                 window.location.href = "/signIn";
             },
             error: function (error) {
-                alert('密码修改失败');
+                alert(error.responseText);
             }
         });
     }

+ 3 - 3
src/main/webapp/resources/js/account/signIn.js

@@ -24,7 +24,7 @@ function login() {
             window.location.href = "/enterprise";
         },
         error: function (error) {
-            alert('账号或密码错误');
+            alert(error.responseText);
         }
     });
 }
@@ -59,7 +59,7 @@ function register() {
             window.location.href = "/signIn";
         },
         error: function (error) {
-            alert('注册失败');
+            alert(error.responseText);
         }
     });
 }
@@ -165,7 +165,7 @@ function resetPwd() {
             $('#forgetPwd').modal('hide');
         },
         error: function (error) {
-            alert('邮件发送失败,请重新填写');
+            alert(error.responseText);
         }
     });
 }

+ 13 - 0
src/main/webapp/resources/js/common/base.js

@@ -100,6 +100,8 @@ function highlight(text, words, tag) {
 function highLightKeywords(text, words, tag) {
     if (isEmpty(words)) {
         return text;
+    } else {
+        words = trimStr(words);
     }
     // 默认的标签,如果没有指定,使用span
     tag = tag || 'span';
@@ -125,4 +127,15 @@ function highLightKeywords(text, words, tag) {
         text = text.replace(re, '<' + tag + ' class="highlight">$&</' + tag + '>');
     }
     return text;
+}
+
+/**
+ * 去除首尾空格
+ *
+ * @param str 输入字段
+ *
+ * @returns {void|string|XML}
+ */
+function trimStr(str) {
+    return str.replace(/(^\s*)|(\s*$)/g, "");
 }

+ 2 - 2
src/main/webapp/resources/js/common/invite.js

@@ -127,7 +127,7 @@ function deleteInfo(enUU) {
             }
         },
         error: function (error) {
-           alert('清除失败');
+            alert(error.responseText);
         }
     });
 }
@@ -147,7 +147,7 @@ $('#okay').click(function () {
             }
         },
         error: function (error) {
-            alert('更新失败');
+            alert(error.responseText);
         }
     });
 })

+ 2 - 2
src/main/webapp/resources/js/common/schedular.js

@@ -128,7 +128,7 @@ function deleteInfo(id) {
             getList(20, 1, null);
         },
         error: function (error) {
-            alert('删除失败');
+            alert(error.responseText);
         }
     });
 }
@@ -164,7 +164,7 @@ $('#okay').click(function () {
             getList(20, 1, null);
         },
         error: function (error) {
-            alert('注册失败');
+            alert(error.responseText);
         }
     });
 });