Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Check if there is an open PR about that.
If there isn't, fork it, fix it, make a PR.
It'll be a great exercice. Don't just wait. -
Isn't it usually just
axios(blablabla)
.then(() => {})
.catch(() => {
// oof
});
I've never had problems with that. :/ -
@karasube Thank you for the advice, I'm afraid I will make the code even worse because of my PR as I don't have good knowledge of JS yet
@PrivateGER
In my case, catch() only able to handle exception from javascript side, not server side.
When I return something from with status code 400, it goes to .then(res) with undefined res value and then trigger catch() which says my res is undefined (which makes me unable to get error message from server).
My temporary solution is returning 200 code with error message if something happen (I have deadline H-3 so I need to use hacky way).
Sorry for the long post -
@stupidbot your code will be reviewed before being merged. You will receive suggestions and critical commentary.
Don't worry ;). We all start with something! -
Try async/await. With try/catch.
If other code then 2xx is responed axios throws error and you can go to catch Block
Related Rants
Axios docs recommend me to use catch() callback for server error
- Not working
Then in git issue someone told to provide error callback as second parameter in then()
- Not working
And I just sit here wondering why it return undefined result when the server return 400 :s
rant
axios