1

I am facing an issue that I don't know how to solve. I am developing a small web app in Angular 4. In that application, I make http request to an api I developed in Node.js - Express hosted in our company network.

My problem is that most of the time those calls to the api work perfectly fine. I got no problem in my dev environment, at my home, and in some of our customers networks. But in some networks, the http request does not perform.

I know that because I register every call in the api, and in those cases I do not even detect the call. In Chrome, I even get a 404 error. Furthermore, I installed Postman on a customer's computer, and still no response. I assume it is a network policy which inteferes with the api calls, but I do not know what I am looking for (proxy ?).

Can you give me some hints ? Is it possible to detect those problems in my code and maybe show a message to the customers in that case ?

I can paste some parts of my code if needed.

Thank you!

Edit : I found what caused my problem. My api used an uncommon port (3088), and this port was sometimes blocked by customers network policy. I switched to the port 443 and now it runs pretty well.

1 Answer 1

1

So you have a couple of options assuming you are using angulars HTTP service, as you can see the request here returns an observable, you can then subscribe to that and handle the error.

getConfig(): Observable<HttpResponse<any>> {
    return this.http.get(this.configUrl);
}

showConfig() {
  this.configService.getConfig()
  .subscribe(
    (data: Config) => this.config = { ...data }, // success path
    error => this.error = error // error path
  );
}

You can also retry the request like so

getConfig() {
  return this.http.get<Config>(this.configUrl)
   .pipe(
     retry(3), // retry a failed request up to 3 times
     catchError(this.handleError) // then handle the error
  );
}

You can then pop up a toast message to tell the user about the error if it occurs, here's the source material from Angular's documentation: https://angular.io/guide/http.

Hope this helps.

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

1 Comment

Thank you for your reply, i will implement the route for errors in the subscribe part of my services calls.

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.