From bff8a1ea78c83d81e89da702a004b823ef9e272f Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 3 Jun 2024 16:39:57 +0800 Subject: [PATCH] =?UTF-8?q?request=20=E5=A4=84=E7=90=86errcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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 })