diff --git a/src/models/activities.js b/src/models/activities.js index 9d5b4a1db1c20c39e06c69582a3f31af99300a2e..262fc082a47441a4cc0e7116ac712eb324527f72 100644 --- a/src/models/activities.js +++ b/src/models/activities.js @@ -17,7 +17,7 @@ export default { const response = yield call(queryActivities); yield put({ type: 'saveList', - payload: response, + payload: Array.isArray(response) ? response : [], }); yield put({ type: 'changeLoading', diff --git a/src/models/list.js b/src/models/list.js index 8d74663ff525b0b359209aaa34dfaeacc7800d27..96742257a6964f6cb243340438cafcd657156e14 100644 --- a/src/models/list.js +++ b/src/models/list.js @@ -17,7 +17,7 @@ export default { const response = yield call(queryFakeList, payload); yield put({ type: 'save', - payload: response, + payload: Array.isArray(response) ? response : [], }); yield put({ type: 'changeLoading', diff --git a/src/models/project.js b/src/models/project.js index 54a60147dbddb835dd2c2e4c4532094d29b2f648..4ad17d820e9621aa7658b1ab933d99d1112157d6 100644 --- a/src/models/project.js +++ b/src/models/project.js @@ -17,7 +17,7 @@ export default { const response = yield call(queryProjectNotice); yield put({ type: 'saveNotice', - payload: response, + payload: Array.isArray(response) ? response : [], }); yield put({ type: 'changeLoading', diff --git a/src/utils/request.js b/src/utils/request.js index 5bc56370d36479d0b7ac1752893b0e91b7943632..5361b242c49e95d8af8b54e3abb21c074e74ab98 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -5,24 +5,9 @@ function checkStatus(response) { if (response.status >= 200 && response.status < 300) { return response; } - - return response.json().then((result) => { - if (result.code) { - notification.error({ - message: result.name, - description: result.message, - }); - } - if (result.stack) { - notification.error({ - message: '请求错误', - description: result.message, - }); - } - const error = new Error(result.message); - error.response = response; - throw error; - }); + const error = new Error(response.statusText); + error.response = response; + throw error; } /** @@ -49,5 +34,18 @@ export default function request(url, options) { return fetch(url, newOptions) .then(checkStatus) .then(response => response.json()) - .catch(err => ({ err })); + .catch((error) => { + if (error.code) { + notification.error({ + message: error.name, + description: error.message, + }); + } + if ('stack' in error && 'message' in error) { + notification.error({ + message: `请求错误: ${url}`, + description: error.message, + }); + } + }); }