Skip to content

Error Handling ​

Write it once; it works everywhere. This is where the design saves the most code.

The failure shape ​

json
{ "ok": false, "kind": "validation", "message": "…", "errors": { "email": ["Already taken"] } }
kindSourceWhat the browser does automatically
validationServerPaints errors next to the matching fields
policyServerToast
serviceServerToast (with your message)
expiredServerAsks the user to reload
conflictServerA call carried an old rev
fatalServer / unparseable responseFixed-text toast + error report
debugdd()Shows the debug panel
networkBrowser onlyFixed-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:

php
return LinkerResponse::validation($errors)
    ->catch('state.set', ['scope' => 'wizard', 'key' => 'step', 'value' => 2]);

Offline or server unavailable ​

Situationkind / reasonUser seesReported
fetch fails (offline, DNS)network / offlineToast + offline bannerNo
502/503/504 that isn't Linker JSONnetwork / unavailableToastNo
500 or unparseablefatalToastYes; details only with APP_DEBUG=true

Five rules:

  1. Messages are fixed text (lang/*/linker.php). Server exception messages never reach the screen.

  2. Input stays on screen and is never written to persistent storage. On failure then doesn't run, so form.reset never happens.

  3. 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>
  4. Tokens aren't swapped to make a retry work. A 419 still returns expired.

  5. The site-wide banner's text is in the template: partials/offline-banner.blade.php.

Compared: traditional vs Linker ​

js
// 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(); }
blade
{{-- Linker: this is all --}}
<button type="button" data-linker-call="create" data-linker-args="form">Create</button>