Statuses as types — RPC · Hono

Three habits that answer correctly and tell the client nothing: a .then() chain, c.notFound(), and c.json() without a status. Fix each on a cats API that reads from an asynchronous store, and read a refusal with parseResponse.

What you will learn

Read the theory for Statuses as types

All RPC lessons

All Hono courses

loading types…

What you'll learn

  • Write every status in c.json() so each becomes a member of the route's response type
  • Answer a missing resource with c.json({ error }, 404) instead of c.notFound(), which the client sees as unknown
  • Use async/await in handlers rather than a .then() chain, and read a body or a refusal with parseResponse and DetailedError