If you’re getting the error “SyntaxError: Unexpected token ‘<‘, “<br /><b>”… is not valid JSON”, it’s probably because the server is giving an HTML page with an error as response. The best way to fix the problem is to identify what’s the problem server-side: change response.json() with response.text() and treat the consequent data with JSON.parse(text) in a try…catch statement.
Before:
//fetch() ...
.then(response => response.json())
.then(data => {
//...
After:
//fetch() ...
.then(response => response.text())
.then(data => { try {
console.log(JSON.parse(data));
} catch (e) {
console.error('Error parsing JSON:', data);
}
//...
Most probably you will now be able to read in the developer console (F12) what the response is, being able to identify the server-side problem to fix.
If this wasn’t helpful yet, try give a look on this StackOverflow thread.