@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55import { requestId } from 'hono/request-id'
66import { Hono } from 'hono/tiny'
77import { app } from '../_backend/plugins/channel_self.ts'
8+ import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+ import { backgroundTask } from '../_backend/utils/utils.ts'
810
911const functionName = 'channel_self'
1012const appGlobal = new Hono < MiddlewareKeyVariables > ( ) . basePath ( `/${ functionName } ` )
@@ -23,7 +25,7 @@ appGlobal.all('*', (c) => {
2325 console . log ( 'Not found' , c . req . url )
2426 return c . json ( { error : 'Not Found' } , 404 )
2527} )
26- appGlobal . onError ( ( e , c ) => {
28+ appGlobal . onError ( async ( e , c ) => {
2729 console . log ( 'app onError' , e )
2830 c . get ( 'sentry' ) ?. captureException ( e )
2931 if ( e instanceof HTTPException ) {
@@ -33,6 +35,21 @@ appGlobal.onError((e, c) => {
3335 }
3436 return c . json ( { status : 'Internal Server Error' , response : e . getResponse ( ) , error : JSON . stringify ( e ) , message : e . message } , e . status )
3537 }
38+ await backgroundTask ( c as any , sendDiscordAlert ( c as any , {
39+ content : `Function: ${ functionName } ` ,
40+ embeds : [
41+ {
42+ title : `Failed to process ${ functionName } ` ,
43+ description : `Function: ${ functionName } ` ,
44+ fields : [
45+ {
46+ name : 'Error' ,
47+ value : JSON . stringify ( e ) ,
48+ } ,
49+ ] ,
50+ } ,
51+ ] ,
52+ } ) )
3653 return c . json ( { status : 'Internal Server Error' , error : JSON . stringify ( e ) , message : e . message } , 500 )
3754} )
3855Deno . serve ( appGlobal . fetch )
0 commit comments