How to catch/display exception returned from back-end

Viewed 47

I am attempting to catch and display an exception in my front-end, React, that is being thrown by the back-end (spring).

When I debug with Postman, I get the exception in JSON format just like I want-

enter image description here

However, in React I am only receiving the status code

enter image description here

I am stumped by this seemingly simple problem.

Board.js

 DataService.makeMove(move)
            .then(res => {
                //console.log(res.data);
                setIsWhite((prev) => !prev);                
                props.setTheBoard(res.data);
                setStatus(res.data[64]);
                updateMovesList();
            })
            .catch(err => {
                console.log(err)
                //I added a bunch of nonsense console logs to try to find the info but they were mostly undefined as expected
                console.log(err.errMessage)
                console.log(err.message)
                console.log(err.status)
                console.log(err.errReason)
            })

DataService.js

    makeMove(move){
        return axios.post(`${url}`, move);
    }
1 Answers

As I remember you can access it this way:

err.response.data
Related