1. Problem
1.1. Issue
Uncaught (in promise) SyntaxError: Unexpected end of JSON input
1.2. Source Code
return fetch(options.url, options)
.then((response) =>
response.json().then((json) => {
if (!response.ok) {
return Promise.reject(json);
}
return json;
})
);
When i make a program using react, i saw this matter. I confirmed my code(input JSON body), but there was no issue.
2. Solve
return fetch(options.url, options)
.then((response) => {
if (response.status === 200){
return response.json();
}else{
return Promise.reject(response);
}
// Under code can makes asycn problem
// if (response.status === 200){
// response.json().then((json) => {return json});
// } else{
// return Promise.reject(response);
// }
});
In my case, the matter is spring server not send JSON code. Because of Spring Boot Server Security version changed, there was no JSON of 403 CODE.
In these case, you can solve this problem not using response.json from all return.