1+ import * as Sentry from "@sentry/bun" ;
12import type { Handler } from "hono" ;
23import { upgradeWebSocket } from "hono/bun" ;
34
@@ -21,17 +22,35 @@ export const listenSocketHandler: Handler<AppBindings> = async (c, next) => {
2122 await connection . preconnectUpstream ( ) ;
2223 emit ( { type : "stt.websocket.connected" , userId, provider } ) ;
2324 } catch ( error ) {
25+ const errorMessage =
26+ error instanceof Error ? error . message : "upstream_connect_failed" ;
27+ console . error ( "[listen] preconnect failed:" , {
28+ provider,
29+ error : errorMessage ,
30+ stack : error instanceof Error ? error . stack : undefined ,
31+ } ) ;
32+ Sentry . captureException ( error , {
33+ tags : {
34+ operation : "stt_preconnect" ,
35+ provider,
36+ } ,
37+ extra : {
38+ errorMessage,
39+ userId,
40+ } ,
41+ } ) ;
2442 emit ( {
2543 type : "stt.websocket.error" ,
2644 userId,
2745 provider,
2846 error :
2947 error instanceof Error ? error : new Error ( "upstream_connect_failed" ) ,
3048 } ) ;
31- const detail =
32- error instanceof Error ? error . message : "upstream_connect_failed" ;
33- const status = detail === "upstream_connect_timeout" ? 504 : 502 ;
34- return c . json ( { error : "upstream_connect_failed" , detail } , status ) ;
49+ const status = errorMessage === "upstream_connect_timeout" ? 504 : 502 ;
50+ return c . json (
51+ { error : "upstream_connect_failed" , detail : errorMessage } ,
52+ status ,
53+ ) ;
3554 }
3655
3756 const connectionStartTime = performance . now ( ) ;
0 commit comments