3

I am having angular 2 typescript application. I have 3 tabs. When I click on each tab,the data will be displayed in the card.The data is accessed via rest api using angular HTTP service https://angular.io/docs/ts/latest/guide/server-communication.html#!#fetch-data. It returns observable. Most of the time, I get this below error when seen in the chrome browser console : 502 Bad Gateway. After refreshing the page for couple of times it works. How to fix this issue? Is it the problem with navigation between the tabs breaking the network? By adding retryWhen method of observable in my service would fix the problem?

GET http://restapi/api/data 502 (Bad Gateway) Failed to load resource: the server responded with a status of 502 (Bad Gateway)

the_mishra
  • 813
  • 9
  • 24
user2301
  • 1,857
  • 6
  • 32
  • 63
  • `502 (Bad Gateway)` often refers that the data received by the server is invalid, so cross-check the data what you are sending. – Sravan Sep 06 '17 at 12:04
  • 1
    Actually, 502 means that the server you are using is trying to talk to another server and it failed. – Faron Sep 06 '17 at 12:08
  • @Faron So it is the problem with the server, where I am requesting for the data? How can I fix it from client side? – user2301 Sep 06 '17 at 12:11
  • 2
    You can retry the operation but be aware that you can get into a looping issue. As a good net-citizen, you would write your code to retry a few times and then give up. You should also add a wait time between retry requests in case the upstream server is failing due to requests coming in too fast. For example, wait 1 sec between the 1st request and the 2nd. Wait 2 sec between the 2nd and 3rd requests, Wait 5 sec between the 3rd and 4th requests, etc. – Faron Sep 06 '17 at 12:19
  • @Faron ok. Thanks. I tried this way `.retryWhen((error) => error.delay(5000).take(3))` But no much difference, still sometimes network breaks. – user2301 Sep 06 '17 at 15:05
  • 1
    If you know the developers that built the server, you could let them know the server is having issues. However, this is a good exercise for building an app that has good error handling. – Faron Sep 06 '17 at 15:08

0 Answers0