Reputation: 90
I have a problem to get my custom error message from the server.
I'm using axios to make the call and Express as a server.
I got the status of the error but don't success to get the message only the status.
Express-Server response
res.status(420).json({ message: "some problem" });
react axios call
export function* deleteItem(action) {
try {
yield put(actions.deleteItemStart());
yield axios.delete("/items/item/" + action.itemId);
yield put(actions.deleteItemSuccess());
} catch (error) {
console.log(error);
yield put(actions.deleteItemFailed(error));
}
}
this the error I get without the message
Error: Request failed with status code 420
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:61)
this is my first post I hope it's all clear.
thanks in advance Gilad :)
Upvotes: 1
Views: 233
Reputation: 346
actually you can get axios errors with
catch(e){
console.log("error response:", e.response);
}
e.response contains the server response if there is one.
Upvotes: 1