前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >前端如何获取http状态码400的返回值

前端如何获取http状态码400的返回值

作者头像
蓓蕾心晴
发布2018-04-12 14:05:04
4.3K0
发布2018-04-12 14:05:04
举报
文章被收录于专栏:前端小叙
代码语言:javascript
复制
axios.get("/check_mobile_and_sent_code",{withCredentials:true,params:{mobile:formInline.mobile}}).then(res=>{
                        console.log(res);
                        //if(res.result==true){
                            if (!this.timer) {
                                this.count = this.TIME_COUNT;
                                this.show = false;
                                this.timer = setInterval(() => {
                                    if (this.count > 0 && this.count <= this.TIME_COUNT) {
                                        this.count--;
                                    } else {
                                        this.show = true;
                                        clearInterval(this.timer);
                                        this.timer = null;
                                    }
                                }, 1000)
                            }
                        //}
                    }).catch(error=>{
                        console.log(error.response.data);
                        console.log(error.response.status);
                        console.log(error.response.headers); 
                        console.log('Error', error.message);
                        console.log(error.config);
                    })

使用场景:

当后端判断验证的手机号已存在的时候会返回400,这时需要跳到error条件中,得到后台400的返回数据如上。

以下是error.response返回值:

这里如果直接输出error,等于error.message

附状态码为200的返回值:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-09-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档