What you'll learn: By the end of this lesson you will be able to list the ways a browser application fails and where each one starts, tell which signal reports each kind (a rejected promise, a resolved error status, a window error, an unhandled rejection, a render error), spot the failures that report nothing, and write a failure-mode register for a page with a detection, a containment and a recovery for each row.
Think of a pilot's checklist. It is not a list of what usually goes wrong, it is a list of the ways a flight can go wrong, each with how you would notice and what you do next. A front-end application flies on a machine, a network and other people's services that its authors do not control, so it deserves the same discipline: name the failures before they happen.
This lesson is a map, not a repair manual. The planned lessons Graceful Degradation, Error Boundaries and Global Error Handling and Error Reporting and Source Maps cover the response and the collection. For the server's side, see Failure Handling End to End.
The running example is a checkout page of a grocery marketplace: a basket kept in browser storage, a price and stock request, an address form, a payment widget from a third-party provider and a lazily loaded "order summary" section. All times and counts are illustrative.
The core idea
- A failure mode is a way to fail, how it shows and what contains it. "The API is down" is an event; "a request resolves with a 503 and the page treats the error body as data" is a failure mode.
- Front-end failures happen on machines you cannot see. A back end writes a log line. A browser fails in front of one user, and unless the page reports it, nobody on the team knows.
- Different failures use different signals, and some use none. A failed network request, an HTTP error, a thrown render error and a promise nobody handled each arrive differently, and a missing script may produce only a section that never appears.
Where a front end can fail
Figure 1. The path from a user to the data, and where it breaks
How to read this: every box is a place where something can go wrong, and the page sits at the far left, where nobody on the team is watching. The tab is itself a failure site: its storage can fill and its code can throw.
Network and requests
A request can fail in three shapes. MDN says a fetch() promise only rejects when the request fails, for example a network error, and does not reject for HTTP error statuses such as 404 or 504: code must check Response.ok or Response.status. A request can also never finish: AbortSignal.timeout() aborts with a TimeoutError DOMException, and MDN says its timeout is based on active time, paused while a document is in the back-forward cache. See Request Cancellation, Timeouts and Race Conditions.
Do not trust the browser's online flag. MDN says navigator.onLine is inherently unreliable (a LAN connection counts as online even without internet access), so use it only for hints.
Illustration 1: the minimal example
Three small failures, run in Node: a 404 that does not reject, a truncated saved value that does not parse, and a missing module that rejects.
const missing = new Response("gone", { status: 404 });
console.log("404 resolves, ok:", missing.ok);
try {
JSON.parse('{"cart": [1, 2');
} catch (error) {
console.log("truncated JSON:", error.name);
}
await import("./does-not-exist.mjs").catch((error) => console.log("import rejected:", error.constructor.name, error.code));
Output, from running it as an .mjs file in Node 26.13.1:
404 resolves, ok: false
truncated JSON: SyntaxError
import rejected: Error ERR_MODULE_NOT_FOUND
The 404 resolved, so a try/catch alone would treat it as success. The truncated value throws only when read. The import rejects, and in Node the error is a plain Error; MDN says browsers reject a failed module fetch with a TypeError. These lines show the shapes in Node, not what a browser prints.
Delivery: stale assets after a deploy
A user can keep a tab open for days. Meanwhile the site is deployed again, and the hosting service may delete the old files. Vite's documentation describes exactly this: a new deployment may remove assets from previous deployments, so a page that is still running old code requests chunks that no longer exist. Vite emits a vite:preloadError event when a dynamic import fails to load, and its example reloads the page; the docs also say to serve the HTML with Cache-Control: no-cache, "otherwise the old assets will be still referenced".
MDN says a dynamic import() rejects if the module fetch fails, which in browsers includes an HTTP error such as 404 or 500. A failed fetch is removed from the module map so a later import can retry, but the HTTP cache may still supply a cached error response, so "just retry" works only sometimes.
Figure 2. A tab that outlives a deploy
How to read this: the failure is the gap between v1 and v2, invisible in testing because a test never keeps a tab open across a release. The planned lesson on version skew and cache-busting deployments treats the fix.
Storage and the device
The tab keeps state in storage that you do not fully control. MDN lists the ways it fails:
- Full. Once the limit is reached, browsers throw a
QuotaExceededError; wrap writes intry...catch. - Unavailable. Some browsers have settings that disable the storage API without hiding the global object, and in private browsing some give an empty
localStoragewith a quota of zero. - Gone. Under storage pressure the browser deletes data from the least recently used origin unless the origin has been granted persistence.
- Wrong. Web Storage keeps only strings, so a value written by an older release or cut short must be read defensively, as the truncated JSON above shows.
State Persistence and Synchronization, Browser Storage Options and IndexedDB and Storage Quotas cover the defences. The failure-mode view is the rule: a page whose basket lives in storage needs a defined behavior for full, unavailable, evicted and corrupt.
Code: errors, and which signal reports them
Code fails in several places, and the browser has a different hook for each.
Figure 3. Which hook sees which error
while rendering"| B["Error boundary"] A -->|"script error, thrown
synchronously"| C["window error event"] A -->|"rejected promise,
no handler"| D["unhandledrejection event"] A -->|"HTTP 404 or 503
fetch resolved"| E["Data layer must check
ok or status"]
How to read this: pick the hook by the kind of failure. A global listener for one kind does not see the others, and a status code never reaches any of them unless the data layer turns it into an error.
- React's documentation says an error boundary catches errors thrown while rendering its children, but not errors in event handlers, in server rendering, in the boundary itself, or in asynchronous code such as
setTimeoutcallbacks. It also says there is currently no way to write one as a function component. - MDN says the window
errorevent is generated for script errors thrown synchronously, such as during initial loading or in event handlers, and that a promise rejected with no handler firesunhandledrejectioninstead. - MDN adds that rejections from a cross-origin script do not fire
unhandledrejection, because the event could leak data: a third party's failures may never reach your listener.
Two more families sit here. Too slow is a failure even when nothing throws: MDN defines a long task as an uninterrupted period of 50 ms or more on the main UI thread, with high input latency and janky scrolling among the effects (the interface is experimental and not Baseline, so use it as a measurement aid). And time is unreliable: MDN says a timeout can fire late if the page is busy, and browsers enforce a minimum timeout delay in inactive tabs, so a poll in a background tab drifts. See The Event Loop and the Main Thread.
Third parties and the user's environment
A checkout page often loads a payment widget, an analytics tag and a consent banner from other origins. A classic script without async, defer or type="module" is fetched and executed before the browser continues parsing, so a slow or failing provider can hold up the rest of the page (MDN: it blocks parsing, not rendering). A provider outage, a blocked domain or a content blocker all look the same from the page: the thing is not there. See Third-Party Scripts and iframe Sandboxing.
Decide for each third party whether the page works without it, and test that state on purpose: the payment widget is essential, the analytics tag is not.
Cascades: when a small fault grows
The Google SRE book defines a cascading failure as "a failure that grows over time as a result of positive feedback", names overload as the most common cause and warns that retries can destabilize a system. It lists client behavior among the contributors: a sync protocol that retries aggressively after a failure, and a software update that clears a client's cache. For a front end, treat your own reactions (retries, reloads after an error, polling loops) as load. See Client Retries, Exponential Backoff and Jitter and the companion lesson Resilient UI and Client-Side Circuit Breakers (named in plain text).
Illustration 2: the realistic example, a failure-mode register
A register is a table the team keeps next to the page. One row per failure mode, with what the user sees, how you would know, what contains it and how it recovers. For the checkout page:
| Failure mode | What the user sees | Detection | Containment and recovery |
|---|---|---|---|
| Price API returns 503 | Price missing | Data layer sees the status | Last known price with its age, or an error with retry; no checkout without a price |
| Request hangs | Spinner forever | TimeoutError from a per-call timeout |
Total deadline, one retry, then an error state |
| Old tab after a deploy | Order summary never opens | vite:preloadError or a rejected import |
Offer a reload, after saving the draft |
| Basket storage full or unavailable | Basket not saved | QuotaExceededError or a failed feature test |
Keep the basket in memory and warn |
| Saved basket corrupt | Crash on load | Parse error or failed validation | Discard what is invalid, start an empty basket |
| Payment widget blocked | Pay button missing | No widget at a deadline | Message and an alternative; report it |
| Component throws on render | Blank section | Error boundary | Boundary around the section, reset on user action |
The value is that every row has a named detection and a named recovery; a gap is a bug you can see before an incident does.
Illustration 3: the failure that reports nothing
The row to fear reports nothing. Suppose a browser extension blocks the payment provider's script: no request in your logs fails, nothing is thrown, and the user sees a checkout with no way to pay. The only signal is the absence of the widget at a deadline, which the page must check itself (for example, no widget five seconds after load), and the only way to know how many users it hits is to report that check. MDN's script page says an error event is sent to the element when a script is blocked by its response type, and does not say what happens for a network failure, so do not depend on that event alone.
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Keep a failure-mode register | Gaps are visible before an incident | Needs upkeep as the page changes |
| A boundary around each section | A broken section does not blank the page | More fallbacks to design |
| Detect missing third parties by a deadline | Catches silent failures | A deadline can fire on a slow but working load |
| Reload on a chunk failure | Fixes version skew quickly | Loses unsaved state |
Build it
This lesson has no lab. The only code is the Node snippet above, which was run for this lesson. No browser behavior was observed: the browser facts come from the cited documentation.
In practice: the checkout page after a release
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
A grocery marketplace ships a release on Tuesday. On Wednesday support reports that "the order summary never opens" and that some customers "cannot pay". The dashboards show healthy servers and normal error rates.
Starting architecture
Figure 4. Starting point: errors go to the console
How to read this: the two failing paths, chunks and the payment script, never reach the dashboards, which only watch the servers.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Wait for support tickets | Nothing | Nothing | Customers find every failure first |
| Report errors and health signals from the page | You see browser failures | A reporting path, privacy care | The reporter can fail or loop |
| A register plus a handler per row | Each failure has a defined response | Design and test time | Rows go stale |
The decision
| Field | Decision record |
|---|---|
| Context | Failures in the browser are invisible and undefined. |
| Decision | Keep a failure-mode register for checkout, with a handler per row: a reload prompt on a chunk load error, a deadline check for the payment widget, defensive reads of the saved basket, a boundary around the summary. Report each with the row name. |
| Consequences, good | Gaps are listed; the next release is checked against the register. |
| Consequences, bad | Handlers to maintain and test. |
| Revisit when | New third parties, storage uses or release practices change the list. |
Rollout and verification
- Write the register first, with an owner per row.
- Reproduce each row on purpose: block the script, fill storage, corrupt a saved value, keep a tab open across a test deploy.
- Check the report path: every handler reports once, with the row name and the release.
The 2 a.m. failure
The reporting handler is added to the window error event. A provider outage makes the reporting endpoint fail, the failure throws inside the handler, the handler is called again for its own error, and a stream of reports hammers an unhealthy service from every open tab.
First three checks: (1) the rate of reports per tab; (2) whether the reporter's own failure is reported; (3) whether it retries without a limit. Mitigation: the reporter never reports its own errors, drops events when it fails and limits how many it sends. Follow-up: a test with an endpoint that always fails, asserting the number of calls stays bounded. This is the SRE book's cascade pattern: the reaction to the failure became the load.
Architect's notes
- Name the failure before the fix. A row in the register is cheaper than a postmortem.
- Count the silent ones. For every dependency ask what the page does if it just does not arrive.
- Match the hook to the failure. Render errors, handler errors, rejected promises and HTTP statuses are four cases.
- Bound your own reactions: retries, reloads and reports.
Common mistakes
- Treating a resolved 404 or 503 as success, or trusting
navigator.onLine. - Assuming an error boundary catches everything.
- Reading saved state without validating it.
- Assuming a third party is always there.
- Reloading on every error, which loses work and can loop, or a reporter that reports its own failures.
Key takeaways
- A failure mode is how something fails, how it shows and what contains it.
- Different failures arrive through different signals; some through none.
fetch()resolves on an HTTP error status; the data layer must check.- A tab can outlive a deploy, and storage can be full, unavailable, evicted or wrong.
- Keep a register with a detection and a recovery per row, and bound your own retries, reloads and reports.
Practice exercises
Exercise 1: Starter (30 min). Run the three-line snippet in Node and say, for each line, which hook in Figure 3 would or would not see the failure in a browser.
Exercise 2: Intermediate (2 hours). Write a failure-mode register of at least eight rows for a page you know, and mark who would notice each failure first.
Exercise 3: Advanced (half day). Design a reporting path that cannot cascade: what it drops, how it limits itself and how you would test it with an endpoint that always fails.
Related reading
In this course:
- Error, Loading and Empty States: how a screen shows a known failure.
- Client Retries, Exponential Backoff and Jitter: retrying without a cascade.
- Request Cancellation, Timeouts and Race Conditions: timeouts and aborting.
- Code Splitting, Lazy Loading and Tree Shaking: the lazy chunks that can go missing.
- State Persistence and Synchronization: reading saved state defensively.
- Failure Handling End to End: the back-end view.
Official documentation
- MDN: Window.fetch() and AbortSignal.timeout(): resolve versus reject, and timeouts.
- MDN: dynamic import() and Vite: Building for production: failed imports and load errors after a deploy.
- MDN: Storage quotas and eviction criteria and Using the Web Storage API: quota, availability, eviction.
- React: Component (error boundaries), MDN: error event and unhandledrejection event: which hook sees which error.
- Google SRE book: Addressing Cascading Failures: positive feedback, overload and retries.