Fetch reliability audit: every client call, timed and retried
Use this audit before changing any fetch in the site pack. It lists each client side fetch, its current timeout and retry handling, and the exact wrapper and exponential backoff policy to add where handling is missing. No server route, field name, or storage key changes.
How to read this audit
Scope is the site pack only: public pages, guides, site script, site style, app shell, and the two passenger book copies. App scripts under app that are not in the site pack are listed as not audited. A call is compliant when it has a timeout, a bounded retry for idempotent or idempotent-keyed work, a try catch at the call site, and no unhandled rejection. A call that is not compliant names the wrapper to add.
Compliant: keep as shipped
Timeout 15000 milliseconds per attempt, at most 3 attempts, retry only on network error, timeout, 408, 429, 502, 503, or 504, exponential backoff, and a caught error shown beside the field or as a status message. Do not add a second retry loop around a compliant call.
Missing: add the wrapper below
One call in the pack has a bare fetch with no timeout, no retry, no abort, and one generic error message for every status. That call is the receipt status fetch. Add the wrapper below to that call only. Every other call keeps its existing wrapper.
Exact wrapper to add to a bare GET fetch
Use this wrapper for the receipt GET. It matches the GET policy already used in the public passenger book script, so the two pages cannot drift. It is for an idempotent GET only. Do not use it for a POST without an idempotency key.
var RECEIPT_TIMEOUT_MS = 15000;
var RECEIPT_MAX_ATTEMPTS = 3;
function isTransientStatus(s){ return s===408||s===429||s===502||s===503||s===504; }
function receiptRetryDelay(attempt,res){
try { var ra = res && res.headers ? res.headers.get('retry-after') : null;
if (ra) { var secs = Number(ra); if (isFinite(secs) && secs>=0) return Math.min(5000, secs*1000);
var when = Date.parse(ra); if (isFinite(when)) { var ms = when - Date.now(); if (ms>0) return Math.min(5000, ms); } }
} catch(e) {}
return Math.min(2000, 500 * Math.pow(2, attempt-1));
}
function waitMs(ms){ return new Promise(function(r){ setTimeout(r, ms); }); }
async function fetchBookingWithRetry(token){
var lastErr = null;
for (var attempt=1; attempt<=RECEIPT_MAX_ATTEMPTS; attempt++){
var ctl = null; var timer = null; var timedOut = false;
try {
ctl = new AbortController();
timer = setTimeout(function(){ timedOut = true; try{ ctl.abort(); }catch(e){} }, RECEIPT_TIMEOUT_MS);
var res = await fetch('/api/publicbook/public/' + encodeURIComponent(token), { headers:{Accept:'application/json'}, cache:'no-store', signal: ctl.signal });
if (timer) clearTimeout(timer);
if (res.ok) return await res.json().catch(function(){ throw new Error('bad-json'); });
var status = res.status || 0;
if (isTransientStatus(status) && attempt < RECEIPT_MAX_ATTEMPTS) { var d = receiptRetryDelay(attempt, res); try{ await res.arrayBuffer(); }catch(e){} await waitMs(d); continue; }
var j = {}; try{ j = await res.json(); }catch(e){}
var err = new Error(serverMessage(j, status)); err.status = status; throw err;
} catch(e) {
if (timer) clearTimeout(timer);
if (e && e.status) throw e;
if (e && e.message === 'bad-json') throw e;
lastErr = e;
if (attempt < RECEIPT_MAX_ATTEMPTS) { await waitMs(Math.min(2000, 500 * Math.pow(2, attempt-1))); continue; }
if (timedOut) { var t = new Error('timeout'); t.status = 504; throw t; }
throw e;
}
}
throw lastErr || new Error('network');
}
Call site policy: wrap the call in try catch, show 404 as link incorrect, show timeout and transient 5xx after the last attempt as try again, show a non transient 4xx server message beside the status body, add a Try again button that calls the load function again, abort the in flight attempt on pagehide, guard against a second load while one is in flight, and end the load call with a catch so no unhandled rejection is left. Never retry 400, 401, 403, 404, 409, or 413. Never retry a POST without an idempotency key and an outbox entry.
Exponential backoff policy for every call
Use one policy per class. Do not mix the GET delay cap with the POST delay cap.
| Class | Timeout per attempt | Max attempts | Retry on | Backoff | Retry-After cap |
|---|---|---|---|---|---|
| Idempotent GET, quote, status, live, receipt | 15000 milliseconds, AbortController per attempt | 3 | Network error, timeout abort, 408, 429, 502, 503, 504 | 500, 1000, 2000 milliseconds, 500 times 2 to the power attempt minus 1, capped at 2000 | 5000 milliseconds, seconds or HTTP date, whichever is sooner |
| POST with idempotency key and outbox, public request, booking request, update, reschedule, cancel | 15000 milliseconds, AbortController per attempt | 3 | Network error, timeout abort, 408, 429, 502, 503, 504 only, same Idempotency-Key on every attempt | 500, 1000, 2000 milliseconds, same formula, capped at 30000 when Retry-After is larger | 30000 milliseconds |
| POST without idempotency key, service worker register, link prefetch, Blob download | No manual timeout added | 1, no retry | Never retry manually. Browser or platform manages the register and the prefetch. Blob download is local and already in try catch. | None | None |
- Drain the response body with arrayBuffer before a retry, so the connection can be reused, as the passenger book GET wrapper does
- Never retry 400, 401, 403, 404, 409, or 413. Those are final. Show the server field message and keep entered entries on the form
- A timeout, empty, or cut short result on a draft or quote is not a booking failure. It retries once more at the same tier, then uses the saved template, as the draft guides state
File by file inventory
Each row is one file in the site pack. Rows with no fetch are listed so a future change does not add a bare fetch to them by mistake.
| File | Call | Try catch, timeout, retry today | Wrapper to add, or keep |
|---|---|---|---|
| public/site.js | POST /api/public/request, form data-request | Try catch per attempt, 15000 millisecond timeout, 3 attempts on 429, 408, 502, 503, 504, backoff 500, 1000, 2000, same Idempotency-Key, outbox kept after timeout or network failure, cleared only after a confirmed ok response, permanent 4xx clears the outbox | Keep. Do not wrap it in a second retry loop. Service worker register in the same file is a promise with catch and no manual retry, keep as shipped. Link prefetch is not a fetch call, keep as shipped. |
| public/index.html | GET /api/publicbook/public/quote, home quote estimator preview | AbortController 15000 milliseconds, 3 attempts on transient status, backoff 500 times 2 to the power attempt minus 1 capped at 2000, Retry-After capped at 5000, sequence guard discards stale responses, session cache 5 minutes, errors rendered in the preview box with a Try again button | Keep. The estimator cache key is service and hours only and never changes a saved quote. |
| public/passenger-book.html | GET quote, GET status by token, GET live stage, POST request, POST submit, POST reschedule, POST cancel | GET uses fetchWithRetry with 15000 millisecond timeout, 3 attempts on 408, 429, 502, 503, 504, backoff capped at 2000, Retry-After capped at 5000, drain body before retry, AbortController chaining. POST uses postWithRetry with 15000 millisecond timeout, 3 attempts on the same transient set, backoff capped at 30000, outbox with Idempotency-Key per payload fingerprint, draft save and restore, busy guard, field errors with focus, and no unhandled rejection because every submit handler is try catch with a finally that clears busy | Keep. This file is the reference GET and POST policy for the wrapper above. |
| public/app/passenger-book.html | Same 7 calls as the public passenger book copy | Same fetchWithRetry and postWithRetry shape as the public copy in this pack, with the same 15000 millisecond timeout, 3 attempts, transient set, and outbox Idempotency-Key | Keep the retry wrapper. Validation divergence between copies is a separate defect already listed in the data integrity audit and is not changed by this audit. |
| public/receipt.html | GET /api/publicbook/public/token, receipt status load | Bare await fetch with cache no-store only. No timeout, no AbortController, no retry, no Retry-After handling, no drain before retry. One try catch around the whole load gives the same link incorrect message for 404 and for 500, and no Try again affordance. The load call at the end of the script has no catch, so a throw outside the inner try would be an unhandled rejection. Blob download in the same file is already in try catch and needs no wrapper. | Add fetchBookingWithRetry above: 15000 millisecond timeout per attempt, 3 attempts, retry only on network error, timeout, 408, 429, 502, 503, 504, backoff 500, 1000, 2000 capped at 2000, Retry-After capped at 5000, drain body before retry, 404 shown as link incorrect, timeout after the last attempt shown as timed out, non transient 4xx shown with the server message, Try again button on failure, abort on pagehide, in flight guard, and a catch on the load call. |
| public/calendar-sync.html | No fetch. Client only calendar file build and Blob download | Build and download are in try catch at the submit handlers. No network call, so no timeout or retry applies | Keep. Do not add a fetch wrapper to a local file build. |
| public/pending.html | No fetch. Local storage scan for outbox and draft keys | Storage reads are in try catch, with a storage availability probe. No network call | Keep |
| public/onboarding-checklist.html | No fetch. Local storage progress only | Storage access is guarded, with an in memory fallback when storage is not allowed. No network call | Keep |
| public/request-demo.html | No direct fetch. Page script only validates required fields and persists a draft. Submit is handled by public/site.js for form data-request | Page submit handler stops the event only on validation failure and otherwise lets the site script submit with its wrapper. Draft store save and load are in try catch | Keep. Do not add a second fetch or a second retry loop in the page script. |
| public/guides/index.html | No fetch. In memory guide search, filters, ranking, and address state | Search and address reads are in try catch. No network call | Keep |
| public/404.html and public/offline.html | No fetch. Session storage return path, copy address, page search, online status, and reload retry | Storage and clipboard paths are in try catch with a fallback message. No network call | Keep |
| public/app/index.html | Script tags for app app.js, boot.js, install.js, and table-scroll.js, plus inline nav drawer, boot fallback, table labelling, and dialog focus | Inline code has no fetch. The app scripts are not in the site pack, so their fetches cannot be audited here and are not claimed in this table | Keep the inline code. Audit the app scripts in the app slice before changing any of them. Do not add a public page wrapper to the app shell. |
| All other public marketing pages and guides | No fetch. Static markup, site script menu, metadata, and table wrappers only | No network call in page code. Site script prefetch uses link prefetch for public pages only, never app or api, at most 12 pages, and skips save data and 2g connections | Keep. Do not add a fetch to a static guide to fix a missing fact. A missing fact stays blank with the field named, as the draft guides state. |
Acceptance checks before you ship a wrapper change
Run each check with the receipt page and one compliant page. Each check names the screen, the field, and the result.
- Receipt GET returns 503 twice then 200: the load retries with 500 then 1000 millisecond backoff, renders the booking, and shows no error
- Receipt GET returns 404: no retry, the status body states that the booking link is not correct, and no receipt file is made
- Receipt GET times out at 15000 milliseconds on every attempt: the status body states that the request timed out, a Try again button appears, and entered token in the address is kept
- Receipt GET returns 429 with Retry-After 2: the load waits 2000 milliseconds, not a fixed 500, and then renders or shows the final error
- Reload during a receipt load: the in flight attempt aborts on pagehide, no unhandled rejection appears in the console, and a second load while one is in flight does not start a second fetch
- Public form POST returns 429 then 200: the same Idempotency-Key is sent on both attempts, one pending entry exists, and the done message shows once
- Passenger book POST returns 400: no retry, the form message names the field, entered entries stay on the form, and the outbox entry is cleared as a permanent rejection
- Quote preview GET returns 503 then 200: the preview renders the quote, a stale response from an earlier service or hours change is discarded, and no saved quote changes
Time every fetch, retry only what is safe to retry
Read the inventory above, add the wrapper to the one bare GET, and keep every compliant call as shipped.