Fetch Error Details

Extract status, headers and body from an HTTP error response.

Code

General
const res = await fetch('https://httpbin.org/status/500');
const body = await res.text();
return {
  ok: res.ok,
  status: res.status,
  statusText: res.statusText,
  headers: Object.fromEntries(res.headers),
  body
};
Browser·fetch() may be limited by CORS

More JavaScript Snippets