reject is not a function;at api request success callback function
来源:11-7 Promise重构 三 对象解构

夏目鲸鱼
2019-11-27
报错
GET http://bl.7yue.pro/v1/function () { [native code] } 404 (NOT FOUND)
VM4458:1 thirdScriptError
reject is not a function;at api request success callback function
TypeError: reject is not a function
at success (http://127.0.0.1:54246/appservice/util/http-p.js:65:13)
at o. (WAService.js:1:1131034)
at MC (WAService.js:1:1091186)
at Function.success (WAService.js:1:1092853)
at WAService.js:1:102995
at C (WAService.js:1:437200)
at i. (WAService.js:1:705916)
at i.emit (WAService.js:1:462750)
at Ws (WAService.js:1:706524)
at WAService.js:1:707745
代码
import {config} from '../config.js'
const tips = {
1: '抱歉',
1005:'appkey无效',
3000: '期刊不存在'
}
class HTTP{
request({url, data={}, method="GET"}) {
return new Promise((resolve, reject)=>{
this._request(resolve, reject, data, method)
})
}
_request(url, resolve, reject, data={}, method="GET") {
//url, data, method
wx.request({
url: config.api_base_url + url,
method: method,
data: data,
header: {
'content-type':'application/json',
'appkey':config.appkey
},
success:(res)=>{
//2,3,4开头, startsWith, endsWith
const code = res.statusCode.toString()
if (code.startsWith('2')){
//使用回调函数将res返回
resolve(res.data)
}
else{
reject()
const error_code = res.data.error_code
this._show_error(error_code)
}
},
fail:(err)=>{
reject()
this._show_error(1)
}
})
}
_show_error(error_code) {
if(!error_code) {
error_code = 1
}
const tip = tips[error_code]
wx.showToast({
title: tip?tip:tips[1],
icon: 'none',
duration: 2000
})
}
}
export {HTTP}
写回答
1回答
-
7七月
2019-11-27
检查 api url,不是视频和接口的问题
012019-11-29
相似问题