I'm working on a React Native application, which fetches an API response from a server. Sometimes, it returns success, but sometimes it catches an error.
The following code is my fetch function:
export default async (url, body = null, method = 'GET') => {
let config = {
method,
};
return await fetch(url, config).then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
}).catch(error => {
console.warn(error); // sometimes it was catched in here
});
};
It was returning various error messages, e.g:
[SyntaxError: JSON Parse error: "\u302\" is not a valid unicode escape]
[SyntaxError: JSON Parse error: Invalid escape character 4]
[SyntaxError: JSON Parse error: "\u740\" is not a valid unicode escape]
I'm already checked my API response through the browser and it didn't find anything wrong with the response. I thought there was something wrong with my ES code maybe.
What is going wrong here...?