Error Handling
Write it once; it works everywhere. This is where the design saves the most code.
The failure shape
{ "ok": false, "kind": "validation", "message": "…", "errors": { "email": ["Already taken"] } }| kind | Source | What the browser does automatically |
|---|---|---|
validation | Server | Paints errors next to the matching fields |
policy | Server | Toast |
service | Server | Toast (with your message) |
expired | Server | Asks the user to reload |
conflict | Server | A call carried an old rev |
fatal | Server / unparseable response | Fixed-text toast + error report |
debug | dd() | Shows the debug panel |
network | Browser only | Fixed-text toast + site-wide offline banner |
Modules write zero lines for this.
Field errors
paintFieldErrors removes the old [data-linker-error] hints on every call, so "the last response wins".
Is the failing field on a hidden step? Use catch to bring the user back:
return LinkerResponse::validation($errors)
->catch('state.set', ['scope' => 'wizard', 'key' => 'step', 'value' => 2]);Offline or server unavailable
| Situation | kind / reason | User sees | Reported |
|---|---|---|---|
| fetch fails (offline, DNS) | network / offline | Toast + offline banner | No |
| 502/503/504 that isn't Linker JSON | network / unavailable | Toast | No |
| 500 or unparseable | fatal | Toast | Yes; details only with APP_DEBUG=true |
Five rules:
Messages are fixed text (
lang/*/linker.php). Server exception messages never reach the screen.Input stays on screen and is never written to persistent storage. On failure
thendoesn't run, soform.resetnever happens.Writes are never retried automatically. The failed attempt may have actually been saved; retrying could create two records. Only explicitly marked reads re-fetch when the connection returns:
blade<button data-linker-call="show" data-linker-args='{"page":2}' data-linker-refresh-on-reconnect>Refresh</button>Tokens aren't swapped to make a retry work. A 419 still returns
expired.The site-wide banner's text is in the template:
partials/offline-banner.blade.php.
Compared: traditional vs Linker
// Traditional: written again in every module
const res = await fetch('/api/customers', { method: 'POST', body });
if (res.status === 422) { paintErrors((await res.json()).errors); }
else if (res.status === 403) { toast('Not allowed'); }
else if (res.status === 409) { toast('Please reload'); }
else if (!res.ok) { showErrorCard(); }
else { reloadList(); }{{-- Linker: this is all --}}
<button type="button" data-linker-call="create" data-linker-args="form">Create</button>