请问大家,我这个小程序分享的代码,如何根据接口返回状态code 去做处理?

onShareAppMessage: function (res) {

let goods_id = this.data.goods_id

let warehouse_id = this.data.warehouse_id

_tip2.default.loading();

var that = this;

wx.getStorage({

key: 'session_key',

success: function success(res) {

_wxRequest2.default.post({

'url': _api2.default.user_initiate_assist_bargain,

'data': {

/* rd3_key: res.data, */

goods_id: that.data.goods_id,

activity_id: that.data.activity_id,

region_id:that.data.address_id

}

}).then(function (res) {

if (res.code == 100) {

let data = res.data

console.log(data,'data87876766')

that.setData({

bargain_order_id:data.bargain_order_id,

share_title:data.title,

share_img:data.img_url,

share_url:data.page_url,

});

} else {

tip.toast(res.data);

}

_tip2.default.loaded();

});

}

});

const promise = new Promise(resolve => {

setTimeout(() => {

resolve({

title: that.data.share_title,

path: that.data.share_url,

imageUrl: that.data.share_img,

})

}, 1000)

})

return {

title: "砍价商品",

path: "/pages/gooddetail/index?id="+goods_id+"&wh_id="+warehouse_id,

imageUrl: '',

promise

}

},

上面的代码,如果后端返回code 为 401 也一样能正常分享 我希望在code 不等于100的时候,就阻止继续分享,并且打印这个报错提示

请问大家,我这个小程序分享的代码,如何根据接口返回状态code 去做处理?


回答:

onShareAppMessage: function (res) {

let goods_id = this.data.goods_id

let warehouse_id = this.data.warehouse_id

_tip2.default.loading();

var that = this;

wx.getStorage({

key: 'session_key',

success: function success(res) {

_wxRequest2.default.post({

'url': _api2.default.user_initiate_assist_bargain,

'data': {

/* rd3_key: res.data, */

goods_id: that.data.goods_id,

activity_id: that.data.activity_id,

region_id:that.data.address_id

}

}).then(function (res) {

if (res.code == 100) {

let data = res.data

console.log(data,'data87876766')

that.setData({

bargain_order_id:data.bargain_order_id,

share_title:data.title,

share_img:data.img_url,

share_url:data.page_url,

});

const promise = new Promise(resolve => {

setTimeout(() => {

resolve({

title: that.data.share_title,

path: that.data.share_url,

imageUrl: that.data.share_img,

})

}, 1000)

})

return {

title: "砍价商品",

path: "/pages/gooddetail/index?id="+goods_id+"&wh_id="+warehouse_id,

imageUrl: '',

promise

}

} else if (res.code == 401) {

console.error('无法分享,错误代码:401');

tip.toast(res.data);

} else {

tip.toast(res.data);

}

_tip2.default.loaded();

});

}

});

},

以上是 请问大家,我这个小程序分享的代码,如何根据接口返回状态code 去做处理? 的全部内容, 来源链接: utcz.com/p/934239.html

回到顶部