鍍金池/ 問答/Linux  HTML/ fetch發(fā)送請求

fetch發(fā)送請求

在封裝的fetch中如何對后臺返回的相同狀態(tài)碼做統(tǒng)一的響應(yīng)
比如:
code=0的時(shí)候 提示成功
code=100的時(shí)候 提示超時(shí)
code=200的時(shí)候 提示系統(tǒng)錯(cuò)誤
目前我是在每個(gè)請求后的回調(diào)函數(shù)中都寫上同樣的代碼
大佬們,有沒有好的解決方案.
先行謝過

回答
編輯回答
心悲涼
responseClient(ctx,httpCode = 500, code = 3,message='服務(wù)端異常',data={}) {
        let responseData = {};
        responseData.code = code;
        responseData.message = message;
        responseData.data = data;
        ctx.status = httpCode;
        ctx.body = responseData;
    }

node.js用這個(gè)來封裝,不知道你用的是不是node.js

2017年5月21日 06:21