1

This is loadSize() function and it calls a getTotalNumberCampaigns() function in my campaignsService class.

 loadSize() {
    this.campaignsService.getTotalNumberCampaigns().subscribe(value => {//async call
        this.campaignSize = value;
    }, (err: any) => { console.log(err.status); console.log(err);}

    );
}

this is my getTotalNumberCampaigns()

 getTotalNumberCampaigns(): Observable<number> {
    return this.http.get(`${this.apiUrl}/Count`, { headers: this.headers })
        .map<any>(res => res.json())
}

I start up the backend api everything works fine, now I stop the api and refresh my page. It will fire the console.log(err.status); console.log(err); since it's connection failed. but I actually got 200 status while in my browser console it says it is a 502 error.

anyone tell me why?

enter image description here

ilse2005
  • 11,189
  • 5
  • 51
  • 75
Bob Zhang
  • 841
  • 3
  • 10
  • 17

1 Answers1

0

In fact, in the case of a connection failure, the response object you receive in your error callback is an error one since the value of its type attribute is 3 (ERROR). What is a bit strange is that it seems that the preflighted request is executed and received a response. Could you give us its details from the Network tab in dev tools (by clicking on "OPTIONS http://localhost:...")?

See this question for more details:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360