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

  • 1
    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.
  • 1
    Isn't it usually just
    .then(() => {})
    .catch(() => {
    // oof

    I've never had problems with that. :/
  • 0
    @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

    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
  • 0
    @stupidbot your code will be reviewed before being merged. You will receive suggestions and critical commentary.

    Don't worry ;). We all start with something!
  • 0
    Can't you just check the response code?
  • 1
    Try async/await. With try/catch.
    If other code then 2xx is responed axios throws error and you can go to catch Block
Add Comment