@@ -14,6 +14,7 @@ import { beforeEach, describe, expect, onTestFinished, test, vi } from 'vitest';
1414import { CloudflareClient } from '../src/client' ;
1515import { withSentry } from '../src/handler' ;
1616import { markAsInstrumented } from '../src/instrument' ;
17+ import * as HonoIntegration from '../src/integrations/hono' ;
1718
1819// Custom type for hono-like apps (cloudflare handlers) that include errorHandler and onError
1920type HonoLikeApp < Env = unknown , QueueHandlerMessage = unknown , CfHostMetadata = unknown > = ExportedHandler <
@@ -1081,10 +1082,12 @@ describe('withSentry', () => {
10811082 } ) ;
10821083
10831084 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 ( ) => {
10861086 const error = new Error ( 'test hono error' ) ;
10871087
1088+ const handleHonoException = vi . fn ( ) ;
1089+ vi . spyOn ( HonoIntegration , 'getHonoIntegration' ) . mockReturnValue ( { handleHonoException } as any ) ;
1090+
10881091 const honoApp = {
10891092 fetch ( _request , _env , _context ) {
10901093 return new Response ( 'test' ) ;
@@ -1100,10 +1103,8 @@ describe('withSentry', () => {
11001103 // simulates hono's error handling
11011104 const errorHandlerResponse = honoApp . errorHandler ?.( error ) ;
11021105
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 ) ;
11071108 expect ( errorHandlerResponse ?. status ) . toBe ( 500 ) ;
11081109 } ) ;
11091110
0 commit comments