5

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?

1 Answer 1

1

After upgrading to Angular 2.3.0 the problem is solved.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you give me details about how to handle this error ?
Sorry @duardbr, I don't understand your question. If an error occurs while doing a get request, the catch returns the reason of the failure. This reason can for example be used to inform the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.