@@ -10,52 +10,46 @@ import {
10
10
spanToJSON ,
11
11
} from '@sentry/core' ;
12
12
import type { IntegrationFn , Span } from '@sentry/core' ;
13
- import { generateInstrumentOnce } from '../../otel/instrument' ;
14
- import { FastifyInstrumentationV3 } from './fastify- v3/instrumentation' ;
13
+ import { generateInstrumentOnce } from '../../../ otel/instrument' ;
14
+ import { FastifyInstrumentationV3 } from './v3/instrumentation' ;
15
15
import * as diagnosticsChannel from 'node:diagnostics_channel' ;
16
- import type { FastifyInstance } from './fastify-v3/internal-types' ;
17
- import { DEBUG_BUILD } from '../../debug-build' ;
18
-
19
- /**
20
- * Minimal request type containing properties around route information.
21
- * Works for Fastify 3, 4 and presumably 5.
22
- *
23
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
24
- */
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- interface MinimalFastifyRequest extends Record < string , any > {
27
- method ?: string ;
28
- // since fastify@4.10.0
29
- routeOptions ?: {
30
- url ?: string ;
31
- } ;
32
- routerPath ?: string ;
33
- }
34
-
35
- /**
36
- * Minimal reply type containing properties needed for error handling.
37
- *
38
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
39
- */
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- interface MinimalFastifyReply extends Record < string , any > {
42
- statusCode : number ;
43
- }
44
-
45
- // We inline the types we care about here
46
- interface Fastify {
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- register : ( plugin : any ) => void ;
49
- addHook : ( hook : string , handler : ( ...params : unknown [ ] ) => void ) => void ;
50
- }
51
-
52
- interface FastifyWithHooks extends Omit < Fastify , 'addHook' > {
53
- addHook (
54
- hook : 'onError' ,
55
- handler : ( request : MinimalFastifyRequest , reply : MinimalFastifyReply , error : Error ) => void ,
56
- ) : void ;
57
- addHook ( hook : 'onRequest' , handler : ( request : MinimalFastifyRequest , reply : MinimalFastifyReply ) => void ) : void ;
58
- }
16
+ import { DEBUG_BUILD } from '../../../debug-build' ;
17
+ import type { FastifyInstance , FastifyReply , FastifyRequest } from './types' ;
18
+
19
+ // /**
20
+ // * Minimal request type containing properties around route information.
21
+ // * Works for Fastify 3, 4 and presumably 5.
22
+ // *
23
+ // * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
24
+ // */
25
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ // interface MinimalFastifyRequest extends Record<string, any> {
27
+ // method?: string;
28
+ // // since fastify@4.10.0
29
+ // routeOptions?: {
30
+ // url?: string;
31
+ // };
32
+ // routerPath?: string;
33
+ // }
34
+
35
+ // /**
36
+ // * Minimal reply type containing properties needed for error handling.
37
+ // *
38
+ // * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
39
+ // */
40
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ // interface MinimalFastifyReply extends Record<string, any> {
42
+ // statusCode: number;
43
+ // }
44
+
45
+ // // We inline the types we care about here
46
+ // interface Fastify {
47
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ // version: string;
49
+ // register: (plugin: any) => Fastify;
50
+ // after: (listener?: (err: Error) => void) => Fastify;
51
+ // addHook: (name: string, handler: (...params: unknown[]) => void) => Fastify;
52
+ // }
59
53
60
54
interface FastifyHandlerOptions {
61
55
/**
@@ -89,7 +83,7 @@ interface FastifyHandlerOptions {
89
83
* });
90
84
* ```
91
85
*/
92
- shouldHandleError : ( error : Error , request : MinimalFastifyRequest , reply : MinimalFastifyReply ) => boolean ;
86
+ shouldHandleError : ( error : Error , request : FastifyRequest , reply : FastifyReply ) => boolean ;
93
87
}
94
88
95
89
const INTEGRATION_NAME = 'Fastify' ;
@@ -157,7 +151,7 @@ export const fastifyIntegration = defineIntegration(_fastifyIntegration);
157
151
*
158
152
* 3xx and 4xx errors are not sent by default.
159
153
*/
160
- function defaultShouldHandleError ( _error : Error , _request : MinimalFastifyRequest , reply : MinimalFastifyReply ) : boolean {
154
+ function defaultShouldHandleError ( _error : Error , _request : FastifyRequest , reply : FastifyReply ) : boolean {
161
155
const statusCode = reply . statusCode ;
162
156
// 3xx and 4xx errors are not sent by default.
163
157
return statusCode >= 500 || statusCode <= 299 ;
@@ -183,11 +177,11 @@ function defaultShouldHandleError(_error: Error, _request: MinimalFastifyRequest
183
177
* app.listen({ port: 3000 });
184
178
* ```
185
179
*/
186
- export function setupFastifyErrorHandler ( fastify : Fastify , options ?: Partial < FastifyHandlerOptions > ) : void {
180
+ export function setupFastifyErrorHandler ( fastify : FastifyInstance , options ?: Partial < FastifyHandlerOptions > ) : void {
187
181
const shouldHandleError = options ?. shouldHandleError || defaultShouldHandleError ;
188
182
189
183
const plugin = Object . assign (
190
- function ( fastify : FastifyWithHooks , _options : unknown , done : ( ) => void ) : void {
184
+ function ( fastify : FastifyInstance , _options : unknown , done : ( ) => void ) : void {
191
185
fastify . addHook ( 'onError' , async ( request , reply , error ) => {
192
186
if ( shouldHandleError ( error , request , reply ) ) {
193
187
captureException ( error ) ;
0 commit comments