OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError: Cannot read properties of undefined (reading 'status') in axios

  • Thread starter Thread starter user7200977
  • Start date Start date
U

user7200977

Guest
This is the code from the freecodecamp tutorial (https://www.freecodecamp.org/news/how-to-build-react-based-code-editor/), the code is meant for react but my project is for next js and when I run it in the react project I don't get this error but when I run it in the next js project I get the error:

Code:
 TypeError: Cannot read properties of undefined (reading 'status')

The code where the error is occurring according to the error message.

Code:
axios
        .request(options)
        .then(function (response) {
            console.log("res.data", response.data);
            const token = response.data.token;
            checkStatus(token);
        })
        .catch((err) => {
            let error = err.response ? err.response.data : err;
            // get error status
            let status = err.response.status;
            console.log("status", status);
            if (status === 429) {
                console.log("too many requests", status);

                showErrorToast(
                    `Quota of 100 requests exceeded for the Day! Please read the blog on freeCodeCamp to learn how to setup your own RAPID API Judge0!`,
                    10000
                );
            }
            setProcessing(false);
            console.log("catch block...", error);
        });
};

<p>This is the code from the freecodecamp tutorial (<a href="https://www.freecodecamp.org/news/how-to-build-react-based-code-editor/" rel="nofollow noreferrer">https://www.freecodecamp.org/news/how-to-build-react-based-code-editor/</a>), the code is meant for react but my project is for next js and when I run it in the react project I don't get this error but when I run it in the next js project I get the error:</p>
<pre><code> TypeError: Cannot read properties of undefined (reading 'status')
</code></pre>
<p>The code where the error is occurring according to the error message.</p>
<pre><code>axios
.request(options)
.then(function (response) {
console.log("res.data", response.data);
const token = response.data.token;
checkStatus(token);
})
.catch((err) => {
let error = err.response ? err.response.data : err;
// get error status
let status = err.response.status;
console.log("status", status);
if (status === 429) {
console.log("too many requests", status);

showErrorToast(
`Quota of 100 requests exceeded for the Day! Please read the blog on freeCodeCamp to learn how to setup your own RAPID API Judge0!`,
10000
);
}
setProcessing(false);
console.log("catch block...", error);
});
};
</code></pre>
 
Top