@@ -7,6 +7,7 @@ import { GrammyError } from 'grammy'
77import { sendMessage } from './llms/utils/helpers'
88import { now } from '../utils/perf'
99import OpenAI from 'openai'
10+ import config from '../config'
1011
1112// const MAX_TRIES = 3 // Define the maximum number of retries
1213
@@ -31,12 +32,16 @@ class ErrorHandler {
3132 Sentry . setContext ( 'llms' , { retryCount, msg } )
3233 Sentry . captureException ( e )
3334 ctx . chatAction = null
35+ const reportAccount = config . llms . reportAcount
3436 if ( retryCount === 0 ) {
3537 // Retry limit reached, log an error or take alternative action
3638 logger . error ( `Retry limit reached for error: ${ e } ` )
3739 return
3840 }
3941 if ( e instanceof GrammyError ) {
42+ if ( reportAccount && ctx . chat ?. id ) {
43+ await ctx . api . sendMessage ( reportAccount , `On method "${ e . method } " in chat ${ ctx . chat . id } | ${ e . error_code } - ${ e . description } ` )
44+ }
4045 if ( e . error_code === 400 && e . description . includes ( 'not enough rights' ) ) {
4146 const errorMsg = 'Error: The bot does not have permission to send photos in chat'
4247 this . writeLog ( ctx , errorMsg , logger )
@@ -70,6 +75,9 @@ class ErrorHandler {
7075 await sendMessage ( ctx , 'Error handling your request' ) . catch ( async ( e ) => { await this . onError ( ctx , e , retryCount - 1 , logger ) } )
7176 }
7277 } else if ( e instanceof OpenAI . APIError ) {
78+ if ( reportAccount && ctx . chat ?. id ) {
79+ await ctx . api . sendMessage ( reportAccount , `${ ctx . session . chatGpt . model } : Error reported in chat ${ ctx . chat ?. id } => (${ e . code } ) ${ e . message } ` )
80+ }
7381 // 429 RateLimitError
7482 // e.status = 400 || e.code = BadRequestError
7583 const errorMsg = `OPENAI Error ${ e . status } (${ e . code } ) - ${ e . message } `
@@ -92,6 +100,8 @@ class ErrorHandler {
92100 } else if ( e instanceof AxiosError ) {
93101 const errorMsg = `${ e . message } `
94102 this . writeLog ( ctx , errorMsg , logger )
103+ console . log ( e . message , e . cause )
104+ console . log ( e . stack )
95105 await sendMessage ( ctx , 'Error handling your request' ) . catch ( async ( e ) => {
96106 await this . onError ( ctx , e , retryCount - 1 , logger )
97107 } )
0 commit comments