Commit 10e8c035 authored by afc163's avatar afc163

Fix API fetch error, close #82

parent 874afcc3
...@@ -17,7 +17,7 @@ export default { ...@@ -17,7 +17,7 @@ export default {
const response = yield call(queryActivities); const response = yield call(queryActivities);
yield put({ yield put({
type: 'saveList', type: 'saveList',
payload: response, payload: Array.isArray(response) ? response : [],
}); });
yield put({ yield put({
type: 'changeLoading', type: 'changeLoading',
......
...@@ -17,7 +17,7 @@ export default { ...@@ -17,7 +17,7 @@ export default {
const response = yield call(queryFakeList, payload); const response = yield call(queryFakeList, payload);
yield put({ yield put({
type: 'save', type: 'save',
payload: response, payload: Array.isArray(response) ? response : [],
}); });
yield put({ yield put({
type: 'changeLoading', type: 'changeLoading',
......
...@@ -17,7 +17,7 @@ export default { ...@@ -17,7 +17,7 @@ export default {
const response = yield call(queryProjectNotice); const response = yield call(queryProjectNotice);
yield put({ yield put({
type: 'saveNotice', type: 'saveNotice',
payload: response, payload: Array.isArray(response) ? response : [],
}); });
yield put({ yield put({
type: 'changeLoading', type: 'changeLoading',
......
...@@ -5,24 +5,9 @@ function checkStatus(response) { ...@@ -5,24 +5,9 @@ function checkStatus(response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
return response; return response;
} }
const error = new Error(response.statusText);
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; error.response = response;
throw error; throw error;
});
} }
/** /**
...@@ -49,5 +34,18 @@ export default function request(url, options) { ...@@ -49,5 +34,18 @@ export default function request(url, options) {
return fetch(url, newOptions) return fetch(url, newOptions)
.then(checkStatus) .then(checkStatus)
.then(response => response.json()) .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,
});
}
});
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment