Function: safe()
safe<
TData,TErrorShape>(promise):Promise<SafeResult<TData,TErrorShape>>
Defined in: packages/client/src/safe.ts:38
Await a vanilla client query() or mutate() call without it throwing, getting back a
[data, error] pair typed with that procedure's error shape.
Type Parameters
| Type Parameter |
|---|
TData |
TErrorShape |
Parameters
| Parameter | Type |
|---|---|
promise | TRPCPromise<TData, TErrorShape> |
Returns
Promise<SafeResult<TData, TErrorShape>>
Example
tsconst [post, error] = await safe(client.post.byId.query({ id }));if (error) {console.error(error);}const id = post.id;
tsconst [post, error] = await safe(client.post.byId.query({ id }));if (error) {console.error(error);}const id = post.id;