Guides

Error handling

Catch, inspect and recover from failed requests.

Catching errors

Every failure rejects with a TempoError carrying status, url, attempts and the parsed body when there is one.

ts
import { TempoError } from "tempo-http";try {  await api.get("/users/42");} catch (error) {  if (error instanceof TempoError && error.status === 404) {    return null;  }  throw error;}

Timeouts

A timeout rejects with error.status === 0 and error.reason === "timeout". It counts as a failed attempt, so it is retried.

Reporting

onError runs once per request, after the last retry, so an error tracker sees one event, not one per try.

Was this page helpful?

Updated