When making a fetch request to the /posts endpoint, I am getting a Type Error along with a message that the Promise object is rejected and has failed to fetch.
What line in your client code are you getting the type error? Also should we be converting the response to json even though it’s already in a json format?
How are you running the JS code that does the fetch?
fetch will reject with a TypeError when a network error is encountered. Check you are running the json server correctly and that it is running on the expected port.
I would however suggest you always have a catch and technically you have to check the response as well.
The Type Error is triggered on the first line before the .then() method is called.
As for the question you asked about me converting it to JSON even though it is already JSON. I checked to see if that was causing the error by printing the result of the first .then() in the console.
@lasjorg, I followed the directions in the documentation of json server so I’m not sure what could be causing the network error.
But there is one thing that does come to mind, that may be causing it. I am currently running JSON Server on Windows Subsystem for Linux and Ubuntu.
In the past I had some issues running certain bash commands because of an issue with my firewall. Do you think that could have anything to do with this?