This is what I came across. Somewhere in the render function of the React component, I have the following:
{first_name} {last_name}
I replaced it with this:
{first_name.toUpperCase()} {last_name.toUpperCase()}
And my application could no longer log in. I use Axios to talk to the backend. Axios is promising. And after I made the changes above. Apparently, he started to execute both the then block and the catch my login API call. When I print the answer in a catch .
function login(data, success, error) { axios.post('/login', JSON.stringify(data), { baseURL: config.apiUrl, headers: { 'Content-Type': 'application/json; charset=utf-8' } }) .then((response) => success(response.data)) .catch((response) => { console.log(response) error(response.status)}) }
I get the following:
TypeError: Cannot read property 'toUpperCase' of undefined
There is absolutely no connection between the component above (it is a mute component that simply displays material from the props on the page) and the API call code.
This is not the first time I encounter this problem in my application. Has anyone ever encountered anything like this before? I understand that my variables in the component are undefined, and why an error occurs. My question is how does it turn into a promise catch block somewhere on the other end of the application.
source share