I have the following scenario:
The backend detects that the token has expired, so it returns 403 with custom “error” response header.
This can be reproduced by firing the following request:
axios.get(MY_URL)
.then(res => console.log("I am expecting to enter this block, and do something with the response header"))
.catch(err => console.log("But instead I skip the Then block and go straight here...));
In Chrome’s networking tab, I can indeed see that the header is there in the response:
<Response headers>
content-type: application/json
error: JWT expired at ......... <-- my header
However, it appears that I go straight into the catch block, where I do not have an access to the response and its headers. I was expecting to go into the then block and do some logic, such as:
.then(res => {
if (res.statusCode === 403 && res.headers['error'] === 'JWT expired at .....') {
// refresh token...
}
});
How can I access my response and its headers, when the then block is skipped?