...
|
...
|
@@ -65,7 +65,7 @@ const request = async({url, method, reqParams = {}, context}) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
const catchError = (context, reqParams) => {
|
|
|
const catchCode = (context, reqParams) => {
|
|
|
return result => {
|
|
|
if (result && result.code === 500) {
|
|
|
createReport(context, 'api')(Object.assign({
|
...
|
...
|
@@ -76,13 +76,22 @@ const catchError = (context, reqParams) => { |
|
|
};
|
|
|
};
|
|
|
|
|
|
export const createApi = context => {
|
|
|
const catchError = (context, store) => {
|
|
|
return error => {
|
|
|
if (error.code === 401) {
|
|
|
store.commit('SET_NEED_LOGIN', {needLogin: true});
|
|
|
}
|
|
|
return Promise.resolve();
|
|
|
};
|
|
|
};
|
|
|
|
|
|
export const createApi = (context, store) => {
|
|
|
return {
|
|
|
get(url, reqParams = {}) {
|
|
|
return request({url, method: 'get', reqParams, context}).then(catchError(context, reqParams));
|
|
|
return request({url, method: 'get', reqParams, context}).then(catchCode(context, reqParams)).catch(catchError(context, store));
|
|
|
},
|
|
|
post(url, reqParams = {}) {
|
|
|
return request({url, method: 'post', reqParams, context}).then(catchError(context, reqParams));
|
|
|
return request({url, method: 'post', reqParams, context}).then(catchCode(context, reqParams)).catch(catchError(context, store));
|
|
|
}
|
|
|
};
|
|
|
}; |
...
|
...
|
|