Search code examples
javascriptjsonfetch

Uncaught (in promise) TypeError: Cannot read property 'json' of undefined


I am taking a javascript course where I have reached the end, and when making a promise, I use the 'fetch' as I have used it in all the code with their respective .then (), but in the latter it throws me this error . I do not know why it can be, I have followed everything to the letter, basically it is an application where orders are entered and they are displayed on the right side of the page, and at this point in the code I am saving the user. I atach pictures below.

ERROR in chrome console

Error in arrow


Solution

  • You have to return the response from the fetch to the next parent promise chain, so add return in the front of fetch call just before the error that you indicated. basically what is happening is that since you are not returning the promise returned by fetch call, so a next 'then' of promise chain has undefined as argument(i.e x here) of callback in it.