Skip to content

Commit

Permalink
feat(fastify): added global error handler on module init in order to …
Browse files Browse the repository at this point in the history
…be set on a runtime level
  • Loading branch information
Stradivario committed Mar 27, 2024
1 parent 35b4d6c commit ed1fbeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/fastify/src/fastify.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class FastifyModule {
for (const schema of schemas) {
instance.addSchema(schema);
}
if (options.globalErrorHandler) {
instance.setErrorHandler(options.globalErrorHandler(instance));
}
return instance;
},
},
Expand Down
10 changes: 10 additions & 0 deletions packages/fastify/src/fastify.tokens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { InjectionToken } from '@rhtml/di';
import {
FastifyError,
FastifyHttpOptions,
FastifyInstance,
FastifyPluginCallback,
FastifyRegisterOptions,
FastifyReply,
FastifyRequest,
FastifySchema,
} from 'fastify';

Expand All @@ -17,4 +20,11 @@ export interface FastifyPlugin {
export interface FastifyModuleOptions extends FastifyHttpOptions<never> {
plugins: FastifyPlugin[];
schemas: FastifySchema[];
globalErrorHandler: (
instance: FastifyInstance
) => (
error: FastifyError,
request: FastifyRequest,
reply: FastifyReply
) => FastifyReply;
}

0 comments on commit ed1fbeb

Please sign in to comment.