【问题标题】:how can i fetech the status_code 400 in angular我如何以角度获取 status_code 400
【发布时间】:2021-07-05 20:49:23
【问题描述】:

我想检查状态码是否=400,以便获取通知

我试过了-

signUp() {
    let body =
    {
        login: this.username,
        nom: this.nom,
        prenom: this.prenom,
        adress: this.adress,
        email: this.email,
        password: this.password,
        date_naissance: this.datenaissance,
        num_tel: this.numTel,
    }

    this.signappService.newsignup(body).subscribe(
        (res: any) => {
            console.log(res)
            this.sucess = true;
            this.failed = false;
        },
        (err) => {
            console.warn(err)
            if (err.status == 400) {
                this.failed = true;
                this.sucess = false;
            }
        });
}

【问题讨论】:

  • 您当前的代码有什么问题?是不工作,还是显示任何错误?
  • 即使在我的控制台中也没有显示任何错误我有错误状态 400
  • 您确定 this.signappService.newsignup(body) 调用的后端实际上正在产生 400 状态响应。您是否尝试过 console.log'ing 错误是什么?
  • 是的,我确信我在试验中故意犯了错误,所以通知出现
  • 是的,我确信我在试验中故意犯了错误,所以通知出现

标签: angular


【解决方案1】:

您好,经过短暂的研究后,我发现了这个答案: Get status code http.get response angular2 您是否在 signappService 的 newsignup 中设置了“{observe: 'response'}”?

【讨论】:

  • 据我所知,只有当您想检查响应代码来自成功的 HTTP 请求时,您才需要它。 catchError 操作符(或订阅方法的错误回调)将返回 EventError 或 HttpErrorResponse。
猜你喜欢
  • 1970-01-01
  • 2022-12-21
  • 1970-01-01
  • 1970-01-01
  • 2022-11-07
  • 1970-01-01
  • 2018-11-25
  • 2021-11-06
  • 1970-01-01
相关资源
最近更新 更多