I followed the tutorial on freecodecamp (https://www.freecodecamp.org/news/how-to-build-react-based-code-editor/) to implement a code editor in React, but I encountered an error when trying to run it in my Next.js project. The specific error message is:
TypeError: Cannot read properties of undefined (reading 'status')
The error is pointing to this section of the 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);
});
};