perf: 请求,统一处理errcode

2.0/email-builder
Lei OT 11 months ago
parent 09125b32ac
commit c5ae7066f6

@ -31,6 +31,14 @@ function checkStatus(response) {
}
}
function checkBizCode(responseJson) {
if (responseJson.errcode === 0) {
return responseJson;
} else {
throw new Error(responseJson.errmsg + ': ' + responseJson.errcode);
}
}
export function fetchText(url) {
const headerObj = getRequestHeader()
return fetch(url, {
@ -58,6 +66,7 @@ export function fetchJSON(url, data) {
}
}).then(checkStatus)
.then(response => response.json())
.then(checkBizCode)
.catch(error => {
throw error;
});
@ -74,6 +83,7 @@ export function postForm(url, data) {
}
}).then(checkStatus)
.then(response => response.json())
.then(checkBizCode)
.catch(error => {
throw error
})
@ -91,6 +101,7 @@ export function postJSON(url, obj) {
}
}).then(checkStatus)
.then(response => response.json())
.then(checkBizCode)
.catch(error => {
throw error
})
@ -108,6 +119,7 @@ export function postStream(url, obj) {
}
}).then(checkStatus)
.then(response => response.json())
.then(checkBizCode)
.catch(error => {
throw error
})

Loading…
Cancel
Save