I want to catch complete errors from fetch
, e.g. I want the red marked stuff as string:
However, in my catch block I only get "Failed to fetch". This is my code:
try {
response = await fetch(url, {
method: method,
body: JSON.stringify(payload),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`RESPONSE NOT OK: ${response.status}`);
}
console.info('got 200 json response:' + (await response?.json()));
} catch (e) {
console.error('CATCH BLOCK:' + e.message); // only gives me "Failed to fetch"
}
So, how can I get the complete fetch error in a string to e.g. show it directly in my webinterface?
Update
Just to clarify this: I know how to fix the error itself. This question is only about how to get the complete error as string.