This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch feature/5.0.0
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking-ui.git

commit a3acdc6039304ea9873c523d12bf38346382cc72
Author: hanahmily <hanahm...@gmail.com>
AuthorDate: Fri Feb 2 11:57:56 2018 +0800

    Add error handler
---
 .../frontend/src/components/Page/Search/index.js   |  3 +--
 src/main/frontend/src/models/alarm.js              | 18 +++++++++++---
 src/main/frontend/src/models/global.js             | 29 +++-------------------
 src/main/frontend/src/utils/request.js             | 14 +++++++++++
 src/main/frontend/src/utils/utils.js               |  3 +++
 5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/src/main/frontend/src/components/Page/Search/index.js 
b/src/main/frontend/src/components/Page/Search/index.js
index 0dba1e0..46eaf24 100644
--- a/src/main/frontend/src/components/Page/Search/index.js
+++ b/src/main/frontend/src/components/Page/Search/index.js
@@ -32,9 +32,8 @@ export default class Search extends PureComponent {
         query,
       },
     })
-      .then()
       .then((body) => {
-        if (fetchId !== this.lastFetchId) { // for fetch callback order
+        if (!body.data || fetchId !== this.lastFetchId) { // for fetch 
callback order
           return;
         }
         this.setState({ data: body.data[Object.keys(body.data)[0]], fetching: 
false });
diff --git a/src/main/frontend/src/models/alarm.js 
b/src/main/frontend/src/models/alarm.js
index 3cdf667..3b9df76 100644
--- a/src/main/frontend/src/models/alarm.js
+++ b/src/main/frontend/src/models/alarm.js
@@ -33,7 +33,11 @@ export default generateModal({
   },
   dataQuery,
   reducers: {
-    saveApplicationAlarmList(preState, { payload: { loadAlarmList } }) {
+    saveApplicationAlarmList(preState, { payload }) {
+      if (!payload) {
+        return preState;
+      }
+      const { loadAlarmList } = payload;
       const { data } = preState;
       return {
         ...preState,
@@ -43,7 +47,11 @@ export default generateModal({
         },
       };
     },
-    saveServerAlarmList(preState, { payload: { loadAlarmList } }) {
+    saveServerAlarmList(preState, { payload }) {
+      if (!payload) {
+        return preState;
+      }
+      const { loadAlarmList } = payload;
       const { data } = preState;
       return {
         ...preState,
@@ -53,7 +61,11 @@ export default generateModal({
         },
       };
     },
-    saveServiceAlarmList(preState, { payload: { loadAlarmList } }) {
+    saveServiceAlarmList(preState, { payload }) {
+      if (!payload) {
+        return preState;
+      }
+      const { loadAlarmList } = payload;
       const { data } = preState;
       return {
         ...preState,
diff --git a/src/main/frontend/src/models/global.js 
b/src/main/frontend/src/models/global.js
index 4a7d34c..c8f419a 100644
--- a/src/main/frontend/src/models/global.js
+++ b/src/main/frontend/src/models/global.js
@@ -49,18 +49,6 @@ export default {
         payload: response.data,
       });
     },
-    *clearNotices({ payload }, { put, select }) {
-      const count = yield select(state => state.global.notices.length);
-      yield put({
-        type: 'user/changeNotifyCount',
-        payload: count,
-      });
-
-      yield put({
-        type: 'saveClearedNotices',
-        payload,
-      });
-    },
   },
 
   reducers: {
@@ -73,19 +61,10 @@ export default {
     saveNotice(state, { payload }) {
       return {
         ...state,
-        notices: payload,
-      };
-    },
-    saveClearedNotices(state, { payload }) {
-      return {
-        ...state,
-        notices: state.notices.filter(item => item.type !== payload),
-      };
-    },
-    changeNoticeLoading(state, { payload }) {
-      return {
-        ...state,
-        fetchingNotices: payload,
+        notices: {
+          ...state.notices,
+          ...payload,
+        },
       };
     },
     changeSelectedTime(state, { payload }) {
diff --git a/src/main/frontend/src/utils/request.js 
b/src/main/frontend/src/utils/request.js
index 6f83dbf..934aa82 100644
--- a/src/main/frontend/src/utils/request.js
+++ b/src/main/frontend/src/utils/request.js
@@ -14,6 +14,19 @@ function checkStatus(response) {
   throw error;
 }
 
+function checkErrors(body) {
+  const { errors } = body;
+  if (!errors) {
+    return body;
+  }
+  errors.forEach((_) => {
+    notification.error({
+      message: _.message,
+    });
+  });
+  throw new Error();
+}
+
 /**
  * Requests a URL, returning a promise.
  *
@@ -40,6 +53,7 @@ export default function request(url, options) {
     .then((response) => {
       return response.json();
     })
+    .then(checkErrors)
     .catch((error) => {
       if (error.code) {
         notification.error({
diff --git a/src/main/frontend/src/utils/utils.js 
b/src/main/frontend/src/utils/utils.js
index 98377e0..0571b0f 100644
--- a/src/main/frontend/src/utils/utils.js
+++ b/src/main/frontend/src/utils/utils.js
@@ -175,6 +175,9 @@ export function generateModal({ namespace, dataQuery, 
optionsQuery, state = {},
     },
     reducers: {
       saveOptions(preState, { payload: allOptions }) {
+        if (!allOptions) {
+          return preState;
+        }
         const { variables } = preState;
         const { values, labels, options } = variables;
         const amendOptions = {};

-- 
To stop receiving notification emails like this one, please contact
hanahm...@apache.org.

Reply via email to