Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios响应拦截器优化建议 #250

Open
yuezhishun opened this issue Mar 10, 2024 · 1 comment
Open

axios响应拦截器优化建议 #250

yuezhishun opened this issue Mar 10, 2024 · 1 comment

Comments

@yuezhishun
Copy link

这里判断接口应答内容中的code字段
在axios的响应拦截器中,判断body中的code会出现接口兼容的问题,建议判断http应答的状态码,理由:工具类尽量避免业务处理,不管http状态码还是body中的状态码,都交给业务代码处理

    // 未设置状态码则默认成功状态
    const code = res.status || 200;

比如图验接口应答里有就会报错

{"code":"1234","uuid":"xxxxxx","img":"xxxxxxxx"}
@yx1314
Copy link

yx1314 commented Mar 21, 2024

我觉得这个你可以写成数组。只要是数组内的code值就都是正常返回值。但是对于项而言。后端的code不统一。很奇怪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants