1

I am requesting a API that throw an error but I cannot get the error message.

This is how the API return the error:

res.status(500).send(JSON.stringify({
                    status: 500,
                    message: "Error during insertion" + err.message,
                }));

This is how I am trying to catch that message.

error: function(res) {
                console.log("Error: " + res.message);
                ierror = 1;

        }

Any idea how i can do it?

2
  • This one SO might help: stackoverflow.com/questions/51036199/… Commented Mar 24, 2020 at 21:26
  • try this: error: function(XMLHttpRequest, status, error) { console.log("Error: "+ error) } Commented Mar 24, 2020 at 21:31

1 Answer 1

1

Parse the incoming string into an Object.

error: function(res) {
            res = JSON.parse(res)  
            console.log("Error: " + res.message);
            ierror = 1;

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.