Skip to content

Commit 0c32c1b

Browse files
committed
fix(plugin): Call the default error mapper function if present
1 parent 7c27851 commit 0c32c1b

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { ShieldContext, ShieldRule } from './rules';
55
type HashFunction = (arg: { root: any; args: any }) => string;
66

77
type ErrorMapper = (
8-
err: Error,
98
parent: any,
109
args: any,
1110
ctx: ShieldContext,

src/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export const nexusShield = (settings: ShieldPluginSettings) => {
9292
: true;
9393

9494
if (!allowed) {
95-
throw options.defaultError;
95+
let error = options.defaultError;
96+
if (typeof error === 'function') {
97+
error = await error(root, args, ctx, info);
98+
}
99+
throw error;
96100
}
97101

98102
// Resolver

tests/fixtures/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const schema = makeSchema({
2828
outputs: false,
2929
plugins: [
3030
nexusShield({
31-
defaultError: new ForbiddenError('DEFAULT'),
31+
defaultError: () => new ForbiddenError('DEFAULT'),
3232
defaultRule: allow,
3333
}),
3434
],

0 commit comments

Comments
 (0)