Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 http does not catch connection refused error

I want to catch all http errors to inform the user of an occurred problem.

So, I created a method that does a http get with a catch.

get(path: string): Promise<any> {
  let headers = new Headers();
  return this.http.get(path, { headers: headers })
    .toPromise()
    .then(response => { ... })
    .catch((response: Response) => { this.errorHandler(response); });
}

When the path parameter is '/fault-url' the catch is handled as expected.

But when the path is 'http://localhost:5000/fault-url' the error is not catched by the catch method. I've added logging to all different places, but it seams the get method just aborts. The console log shows following errors

OPTIONS http://localhost:5000/fault-url net::ERR_CONNECTION_REFUSED

EXCEPTION: Response with status: 0 for URL: null

Uncaught Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers…}

Does http realy abort or am i doing something wrong?

like image 938
Tinie Sluijter Avatar asked Nov 08 '22 04:11

Tinie Sluijter


1 Answers

After upgrading to Angular 2.3.0 the problem is solved.

like image 94
Tinie Sluijter Avatar answered Nov 15 '22 08:11

Tinie Sluijter