Skip to content

Commit

Permalink
refactor: allow ErrorConstructor type for customError (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-michelet authored Jun 30, 2024
1 parent 4d311d6 commit f63e62d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare namespace fastifyUnderPressure {
pressureHandler?: (request: FastifyRequest, reply: FastifyReply, type: string, value: number | undefined) => Promise<void> | void;
sampleInterval?: number;
exposeStatusRoute?: boolean | string | { routeOpts: object; routeSchemaOpts?: object; routeResponseSchemaOpts?: object; url?: string };
customError?: Error;
customError?: Error | (new () => Error);
}

export const TYPE_EVENT_LOOP_DELAY = 'eventLoopDelay'
Expand Down
11 changes: 11 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ const server = fastify();
server.register(fastifyUnderPressure, {
customError: new Error('custom error message')
});

class CustomError extends Error {
constructor () {
super('Custom error message')
Error.captureStackTrace(this, CustomError)
}
}

server.register(fastifyUnderPressure, {
customError: CustomError
});
};

expectType<'eventLoopDelay'>(fastifyUnderPressure.TYPE_EVENT_LOOP_DELAY)
Expand Down

0 comments on commit f63e62d

Please sign in to comment.