@@ -14,6 +14,7 @@ import { beforeEach, describe, expect, onTestFinished, test, vi } from 'vitest';
14
14
import { CloudflareClient } from '../src/client' ;
15
15
import { withSentry } from '../src/handler' ;
16
16
import { markAsInstrumented } from '../src/instrument' ;
17
+ import * as HonoIntegration from '../src/integrations/hono' ;
17
18
18
19
// Custom type for hono-like apps (cloudflare handlers) that include errorHandler and onError
19
20
type HonoLikeApp < Env = unknown , QueueHandlerMessage = unknown , CfHostMetadata = unknown > = ExportedHandler <
@@ -1081,10 +1082,12 @@ describe('withSentry', () => {
1081
1082
} ) ;
1082
1083
1083
1084
describe ( 'hono errorHandler' , ( ) => {
1084
- test ( 'captures errors handled by the errorHandler' , async ( ) => {
1085
- const captureExceptionSpy = vi . spyOn ( SentryCore , 'captureException' ) ;
1085
+ test ( 'calls Hono Integration to handle error captured by the errorHandler' , async ( ) => {
1086
1086
const error = new Error ( 'test hono error' ) ;
1087
1087
1088
+ const handleHonoException = vi . fn ( ) ;
1089
+ vi . spyOn ( HonoIntegration , 'getHonoIntegration' ) . mockReturnValue ( { handleHonoException } as any ) ;
1090
+
1088
1091
const honoApp = {
1089
1092
fetch ( _request , _env , _context ) {
1090
1093
return new Response ( 'test' ) ;
@@ -1100,10 +1103,8 @@ describe('withSentry', () => {
1100
1103
// simulates hono's error handling
1101
1104
const errorHandlerResponse = honoApp . errorHandler ?.( error ) ;
1102
1105
1103
- expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1104
- expect ( captureExceptionSpy ) . toHaveBeenLastCalledWith ( error , {
1105
- mechanism : { handled : false , type : 'auto.faas.cloudflare.error_handler' } ,
1106
- } ) ;
1106
+ expect ( handleHonoException ) . toHaveBeenCalledTimes ( 1 ) ;
1107
+ expect ( handleHonoException ) . toHaveBeenLastCalledWith ( error ) ;
1107
1108
expect ( errorHandlerResponse ?. status ) . toBe ( 500 ) ;
1108
1109
} ) ;
1109
1110
0 commit comments