Function: orThrow()
Function: orThrow()
Section titled “Function: orThrow()”orThrow<
Data>(result):Promise<OrThrowResult<Data>>
Defined in: packages/grabkit/src/orThrow.ts:22
Await a grab and return [data, meta], or throw on failure.
Use when your data layer (TanStack Query, SWR, etc.) expects thrown errors
but you still want success meta (status code, JSON:API links, and so on).
Type Parameters
Section titled “Type Parameters”Data
Parameters
Section titled “Parameters”result
Section titled “result”Promise<GrabResult<Data>>
Promise from a grab call, e.g. grab('GET /users/1').
Returns
Section titled “Returns”Promise<OrThrowResult<Data>>
Example
Section titled “Example”const grab = grabkit('https://api.example.com');const [data, meta] = await orThrow(grab('GET /users/1'));console.log(data.name, meta.statusCode);