In a React app component which handles Facebook-like content feeds, I am running into an error:
Feed.js:94 undefined \"parsererror\" \"SyntaxError: Un
SyntaxError: Unexpected token < in JSON at position 0
Html files begin with .
I "achieved" this error by forgetting the https://
in my fetch
method:
fetch(`/api.github.com/users/${login}`)
.then(response => response.json())
.then(setData);
I logged the response as text instead of JSON.
fetch(`/api.github.com/users/${login}`)
.then(response => response.text())
.then(text => console.log(text))
.then(setData);
Yep, an html file.
I fixed the error by adding back the https://
in my fetch
method.
fetch(`https://api.github.com/users/${login}`)
.then(response => response.json())
.then(setData)
.catch(error => (console.log(error)));