I have one function which checks for user authorization
export const authUser = (rideId, action) => {
return (dispatch, getState) => {
const postData = {
consumer: "Rapi",
classId: rideId,
action: action,
};
return Api.post(
'/api/xx/yy/auth',
postData,
)
.then((response) => {
const authorized = response && response.authorized === true;
if (authorized) {
console.log("User is authorized");
return true;
} else {
console.warn("User is NOT authorized");
return false;
}
})
.catch((error) => {
console.error(" Authorization failed:", error);
return false;
});
};
};
If user is authorized to access this particular ride in that case we are getting this below response from API:
{ "authorized": true }
If that particular RideId is not available or he is not authorized to access that ride we are getting below response from API:
{
"message": "Ride not found. rideId: RD23435OPSMSK76772",
"errorCode": "60000",
"timestamp": "2025-07-02T08:34:57.241+00:00"
}
As of now I am displaying a common message for user not authorized and ride not found error. But I want to display this particular message which we are receiving from API response. When ride Id is not found I am getting above response and catch block is executing. We are getting response in ride not found case, so then .then
block should get executed.
Api.post
to throw an error.