Skip to content

Function: rbacErrorFormatter() ​

ts
function rbacErrorFormatter<S>(opts): S & object;

Defined in: packages/trpc/src/errors.ts:90

An errorFormatter that adds the guard's RbacErrorBody to the error shape as data.rbac (null for other errors), so clients can read error.data.rbac.reason:

ts
const t = initTRPC.context<Context>().create({ errorFormatter: rbacErrorFormatter })

To combine it with your own formatter, call it first and extend what it returns.

Type Parameters ​

Type Parameter
S extends object

Parameters ​

ParameterType
opts{ error: unknown; shape: S; }
opts.errorunknown
opts.shapeS

Returns ​

S & object

Released under the MIT License. Inspired by spatie/laravel-permission.