I am using axios
to make apis calls in react. If there is no token provided or token got expired server sends the 401
status. I want to check that status on reactjs side.
But if i check err object in catch
the status field is null.
Here is the code
try {
MyService.getIntet(reqBody);
} catch (err) {
handleUnAuthorizedResponse(err);
}
on the error this shows this type of info.
In the service
import axios from "axios";
and the function
static getIntent(reqBody) {
const url = `${this.intentionBaseUrl}/process`;
const options = {
headers: {
"Content-Type": "application/json"
},
};
return axios
.post(url, reqBody, options)
.then((res) => res.data)
}
HOw can i handle 401
?