diff --git a/src/utils/request.js b/src/utils/request.js index dcd6def..3c92226 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -45,6 +45,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, { @@ -108,6 +116,7 @@ export function postJSON(url, obj) { } }).then(checkStatus) .then(response => response.json()) + .then(checkBizCode) .catch(error => { throw error })