---
title: "Recipe: send a data module's errors to your server"
description: "A data module hears its errors as a page does."
modificationDate: "2026-11-23"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: send a data module's errors to your server

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/report-errors: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A data module hears its errors as a page does. Listen for `error` and
`unhandledrejection` on the module's global, and send each one to your server from
the listener.

```prompt Send my app's errors to my server
Make the data module of the Exact app in this folder send its errors and unhandled rejections to my server. Use https://github.com/expo/exact/blob/main/docs/recipes/report-errors.md as the source for each step. The Exact checkout has the same page at docs/recipes/report-errors.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say the URL that takes the reports, ask me. The recipe's report holds a `kind` and a `text` (the error's name and message): ask me before a report holds anything more. The server that takes the `POST` is mine to set up.
3. In app.ts, add a separate `net.fetch` line for the reporting origin. Use the full reporting endpoint for the `POST`.
4. Write the `report` function, and listen for `error` and `unhandledrejection` with `addEventListener` on the module's global, as the recipe shows. Call `fetch` in the listener itself, before any `await`, and catch its failure with `.catch(() => {})`. Send a plain HTTP request only. Do not fetch in the reply's `.then`, in a microtask the listener queued, or over a stream or socket: natively, each is refused.
5. In the `catch` of each answer that can fail, call `reportError(e)`, then throw `e` again. A failed answer is not an `error` event: without this call, the answer only fails and no listener hears it.
6. Do not report at bake, during the module's evaluation, or from a worker placement. Do not call `event.preventDefault()` unless I ask: without it, a report also reaches the platform's log.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. Every report still reaches `logs`, whatever a listener does: read them to see what the module reported. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me where the listeners are, which answers call `reportError`, what a report holds, what the tests and checks reported, and what my server must accept. On the web build, the listener is the page's: it hears every error on the page.
```

```contract
component App
  mutation saved as shape string
  action save
    send saved = saveNote()
  view
    column padding=16
      button press=save testId="save"
        text "Save"
```

```ts
import type { Answer, Result } from './app.contract.d.ts';

const API = 'https://api.example.com';
const REPORTS = 'https://errors.example.com';
export const grants = `net.fetch ${API}
net.fetch ${REPORTS}`;

function report(kind: string, reason: unknown): void {
  const text = reason instanceof Error ? `${reason.name}: ${reason.message}` : String(reason);
  // In the listener itself, before any await, with its failure caught.
  fetch(`${REPORTS}/report`, { method: 'POST', body: JSON.stringify({ kind, text }) }).catch(() => {});
}

addEventListener('error', (event) => report('error', event.error));
addEventListener('unhandledrejection', (event) => report('unhandled rejection', event.reason));

export const answer: Answer = async (): Promise<Result<'saveNote'>> => {
  try {
    const response = await fetch(`${API}/notes`, { method: 'POST', body: 'note' });
    if (!response.ok) throw new Error(`The save failed: HTTP ${response.status}.`);
    return 'saved';
  } catch (e) {
    // A failed answer is not an `error` event: report it, then fail the answer.
    reportError(e);
    throw e;
  }
};
```

- **What reaches a listener.** `reportError(e)` and a throw that no code caught (in a
  `queueMicrotask` callback, an abort listener or an answer's timer) are `error`
  events. A rejection that no code handled is an `unhandledrejection` event. An answer
  that throws or rejects only fails (`failure(saved)` in the Contract), so call
  `reportError` in its `catch` to hear it too.
- **What a listener may send, natively.** A plain HTTP request made in the listener
  itself, with `method`, `headers`, `body`, `signal`, `redirect`, `cache` or the
  `exactTimeout` options. No answer waits for it: the answer that called `reportError`
  gives its value first. These are refused:
  - a fetch after an `await`, in the reply's `.then`, or in a microtask the listener
    queued;
  - a stream or socket;
  - a fetch at bake, during the module's evaluation, or on a worker placement;
  - a seventeenth report while sixteen are in flight.

  A report that fails does not set off another.
- **On the web build** the listener is the page's: it hears every error on the page,
  and a fetch it makes later is sent too. A module written as above behaves the same
  on both.
- **What the logs keep.** Every report still reaches `logs` (`data: unhandled
  rejection: …` or `console: Uncaught …`), whatever a listener does. One that no
  listener cancels with `event.preventDefault()` also reaches the platform's log
  (Console.app, logcat or standard error), as a page's console prints it. The full
  rule is in the [reference](https://exact.expo.dev/reference/developer.md).
