I am trying to do the following in ES6 JavaScript, but can't figure out the right syntax. The second .then() works well, but the first one, which should throw an error doesn't (the first part contains standard JS syntax)
return fetch('/api/data.json', {
credentials: 'same-origin'
}).then(function(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
})
.then(response => response.json())
................
.catchat the end to trap that error