3

I have an angular 5 node app. I am sending a request to node server and wait for the reply. Sometimes the response is sent from the server after 5-6 minutes. But after 4 minutes of waiting for the response, the http method throws an ERR_EMPTY_RESPONSE error.

I tried to use timeout() with the method. But it still throws error after 4 minutes.

Is there any way to make the http method wait longer or to avoid this error?

const body = JSON.stringify(params);
const headers = new HttpHeaders({'Content-Type': 'application/json'});
return this.http.post('/api/execute', body, {headers: headers})
  .map((response) => response)
  .catch((error) => Observable.throw(error));
M Reza
  • 18,350
  • 14
  • 66
  • 71

2 Answers2

1

Try setting Keep-Alive header

const headers = new HttpHeaders({'Content-Type': 'application/json', 'Keep-Alive': 'timeout=560'});
David
  • 33,444
  • 11
  • 80
  • 118
0

Browsers have built in time outs, see this thread here Browser Timeouts

So, no, you cannot tell your JavaScript code to wait longer.

Chris
  • 58
  • 1
  • 3