HTTP request error code 429 cannot be caught

Viewed 4245

Using fetchApi I am issuing a POST request to an endpoint and catching errors like this:

fetch(new Request(url, {
  method: 'POST',
  headers: { ...defaultHeaders, ...headers } ,
  credentials: 'include',
  body: JSON.stringify(body)
})).then(
  // handle correct reponse
).catch(
  if (err.status === 401) {
       // handle error nicely
    } else if (err.status === 429) {
       // handle error differently
    } else {
      // handle error yet another way
    }
);

While 401 error is handled as expected, when the endpoint responds with 429 the code

else if (err.status === 429) {
       // handle error differently
    } 

Is never executed.

EDIT1: the entire catch is never reached in case of 429

Are 401 and 429 status codes handled differently by javascript/browsers? How Can I catch 429 error and handle it my way?

1 Answers
Related