diff --git a/backend/src/bot/handle-error.ts b/backend/src/bot/handle-error.ts index 1020104..2e07023 100644 --- a/backend/src/bot/handle-error.ts +++ b/backend/src/bot/handle-error.ts @@ -1,18 +1,24 @@ import type { ErrorHandler } from 'grammy' -import { GrammyError, HttpError } from 'grammy' +import { BotError, GrammyError, HttpError } from 'grammy' import type { Ctx } from './context' /** * @see https://grammy.dev/guide/errors */ -export const handleError: ErrorHandler = (error) => { +export const handleError: ErrorHandler = (e) => { + const error = e.error + const ctx = e.ctx let msg if (error instanceof GrammyError) { msg = 'Bot API request failed' } else if (error instanceof HttpError) { msg = 'network error' - } else { + } else if (error instanceof BotError) { msg = 'error in middleware' } - error.ctx.logger.error({ msg, error }) + ctx.logger.error({ + msg: msg, + update: ctx.update, + error: error, + }) } diff --git a/backend/src/bot/handlers/root.ts b/backend/src/bot/handlers/root.ts index 72c376d..e912cea 100644 --- a/backend/src/bot/handlers/root.ts +++ b/backend/src/bot/handlers/root.ts @@ -23,7 +23,7 @@ export default handler((composer) => { ]]), }) } else { - throw err + throw err.error } })