How does HTTP error-handling work with observables?

后端 未结 2 789
礼貌的吻别
礼貌的吻别 2021-02-05 05:45

I see a lot of tutorials doing something like this:

http.get(\"...\").subscribe(
  success => console.log(\'hello success\'),
  error => console.log(\'bye          


        
2条回答
  •  死守一世寂寞
    2021-02-05 06:20

    It works for me:

    this.http.post('http://example.com/path/', {sampleData: 'd'}).subscribe(
      res => {alert('ok!');},
      err => {alert(err.error)}
    )
    

提交回复
热议问题