bmfe / eros

📱 一套 Vue 代码,两端原生应用 ,或许可以叫我 weex-native。
https://bmfe.github.io/eros-docs
MIT License
2.01k stars 287 forks source link

使用bmAxios的fetch时的问题 #391

Closed nikojxie closed 5 years ago

nikojxie commented 5 years ago

使用bmAxios的fetch,当状态码不在 200-299之间时,无法获得返回的data,只有状态码status和errorMsg,而使用weex官方的 stream.fetch 时,可以获得

PerseveranceZ commented 5 years ago

状态码非200-299 请求都是失败的 这时候data实际不存在 根本没传输过来 为什么要呢

nikojxie commented 5 years ago

后台会封装一些报错信息,比如status是401,报错信息就会返回给前台,是登录过期 有些报错信息需要后台定义 前端展示给用户 这部分信息是在bmAxios.fetch封装的时候就抛掉了吗

nikojxie commented 5 years ago

这是一段使用stream.fetch获得的返回值 {"status":401,"statusText":"Unauthorized","headers":{"Transfer-Encoding":"Identity","X-Application-Context":"getway:dev:8080","Content-Type":"application/json;charset=UTF-8","Date":"Fri, 12 Apr 2019 03:13:50 GMT"},"ok":false,"data":{"code":null,"errors":[],"type":"danger","text":"系统错误:该操作需要登陆才能完成,请登陆系统"}} 当我使用bmAxios.fetch时,data就无法获得

Thanks for your help😊

xiaohuapunk commented 5 years ago

既然请求已到达后端说明 http请求是成功了,此时 http status 就应该是 200,不要修改http协议默认的状态码,你们的data节点不是有 code 字段吗?为什么不用这个code来作业务,而要修改http协议的状态码?eros 底层有封装,非200 就不回返回数据,你可以自己修改一下

nikojxie commented 5 years ago

好的 谢谢你