Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

What Happens After You Call fetch() in JavaScript?

JavaScript fetch() resolves with a Response, not parsed data. Learn how HTTP errors, body reading, CORS, and service workers shape what happens next.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

fetch() returns a promise for a Response, not for parsed JSON. When a response is available, that promise can fulfill even if the HTTP status is 404 or 500. Your code must check the status, then separately read the response body.

What does fetch() return?

Call fetch(resource, options) with a URL or a Request. Options can set details such as the method, headers, body, mode, and credentials; the default method is GET. The browser processes the request according to the Fetch rules, which cover more than sending a message directly to an origin server: redirects, cross-origin checks, content security policy (CSP), and service workers can all affect the path.

As an Amazon Associate I earn from qualifying purchases.

The call returns a promise for a Response. In normal cases, that promise fulfills when a response is available—MDN describes this as happening once the server responds with headers. The response object contains status and header information, while the body is handled separately. See MDN’s Using the Fetch API and the WHATWG Fetch Standard.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why doesn’t fetch() reject on a 404?

A fulfilled fetch promise means the request produced a response; it does not mean the server reported success. HTTP statuses such as 404 Not Found or 504 Gateway Timeout are still responses, so check response.ok or response.status and decide how your application should handle them. response.ok indicates whether the status is in the successful range.

const response = await fetch("/api/data");
if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();

The first await waits for the response. The second waits for the body to be read and parsed as JSON. This is why fetch() does not directly return the parsed value.

When does the fetch promise reject?

It rejects when the browser cannot provide a usable response, rather than simply because the server returned an error status. MDN lists malformed URLs and network errors among possible rejection causes. If code aborts the request through AbortController, the promise rejects with an AbortError. Handle these request failures separately from HTTP error responses; MDN documents the behavior in its Window: fetch() method reference.

What happens when JavaScript reads the response body?

After the fetch promise fulfills, the response body has not necessarily been consumed or parsed by application code. Call a body method such as response.json() or response.text() to read it. These methods return promises, so body reading—and, for json(), parsing—forms a later asynchronous step. A failure in that step is distinct from an HTTP status such as 404.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can CORS change what JavaScript sees?

For cross-origin requests, the default mode is cors. A simple cross-origin request can be sent, but the browser withholds its response from JavaScript unless the server supplies a suitable Access-Control-Allow-Origin header. Some requests require a preflight check before the browser sends the actual request. The exact behavior depends on the request and the server’s CORS response; see MDN’s CORS guidance.

Setting mode: "no-cors" is not a way to read arbitrary cross-origin data. It produces an opaque response: JavaScript cannot access its headers or body.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Can a service worker answer the request?

Yes. A service worker can receive fetch events for explicit fetch() calls and other browser requests. Its handler may return a cached response, synthesize a response, or use the network. If the handler does not call respondWith(), the browser makes the original request. Consequently, the response JavaScript receives is not always a direct reply from the origin server. MDN explains this in its fetch event reference.

How to interpret the outcome

  • Promise fulfilled, successful status: A Response is available with a successful HTTP status; read its body if the application needs it.
  • Promise fulfilled, error status: A response exists, but the HTTP operation was unsuccessful. Check ok or status and handle it explicitly.
  • Promise rejected: No usable response was provided to the caller, for example because of a network failure, malformed URL, or abort.
  • Opaque response: In no-cors mode, JavaScript cannot inspect the response headers or body.
  • Worker-controlled response: A service worker may supply cached or synthesized content instead of relying on the network response.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.