Angular 2 http does not detect connection failed error

I want to catch all HTTP errors in order to inform the user about the problem.

So, I created a method that gets http with 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 processed as expected.

But when the path is " http: // localhost: 5000 / fault-url , the error is not caught by the catch method. I added the registration to all different places, but the seams method get method just aborts. The following errors are displayed in the console log.

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 ...}

Is http-reality interrupted or am I doing something wrong?

+5
source share
1 answer

After upgrading to Angular 2.3.0, the problem is resolved.

+1
source

Source: https://habr.com/ru/post/1261030/


All Articles