LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How do you check if a fetch request was successful?

Check the response.ok property, which is true only for status codes in the 200-299 range.

const response = await fetch('/api/data');
if (!response.ok) {
  throw new Error('HTTP error: ' + response.status);
}
const data = await response.json();

Also available:

  • response.status - numeric code (200, 404, 500)
  • response.statusText - text description ("OK", "Not Found")

From Quiz: WEBT / Backend Integration | Updated: Jun 20, 2026