Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Web

Handling Errors

The web View provides handleError through ViewContext. Call it from the catch block of a request, or use useAPI, which forwards errors to it automatically.

const viewContext = useContext(ViewContext);

async function refresh() {
  try {
    await loadData();
  } catch (err) {
    viewContext.handleError(err);
  }
}

The handler sends a 401 to sign-in, a 402 to the upgrade screen and a 404 to the not-found screen. Rate-limit responses and other request errors appear in a toast. Client-side exceptions are also logged to the console.