refactor: global error handling
This commit is contained in:
parent
7a08f968f4
commit
9a3b3d6bad
@ -13,7 +13,6 @@ const feature = composer.chatType('private');
|
||||
const redis = getRedisInstance();
|
||||
|
||||
feature.on('message:text', logHandle('download-message'), async (context) => {
|
||||
try {
|
||||
const url = context.message.text.trim();
|
||||
|
||||
if (!validateTikTokUrl(url)) {
|
||||
@ -39,8 +38,7 @@ feature.on('message:text', logHandle('download-message'), async (context) => {
|
||||
|
||||
if (result?.type === 'video' && videoUrl) {
|
||||
const { video } = await context.replyWithVideo(new InputFile({ url: videoUrl }));
|
||||
await redis.set(url, video.file_id, 'EX', TTL_URLS);
|
||||
return;
|
||||
return redis.set(url, video.file_id, 'EX', TTL_URLS);
|
||||
}
|
||||
|
||||
if (result?.type === 'image' && imagesUrls) {
|
||||
@ -48,10 +46,6 @@ feature.on('message:text', logHandle('download-message'), async (context) => {
|
||||
imagesUrls.map((image) => ({ media: image, type: 'photo' })),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
context.logger.error(error);
|
||||
return context.reply(context.t('err-generic'));
|
||||
}
|
||||
});
|
||||
|
||||
export { composer as download };
|
||||
|
||||
@ -2,9 +2,11 @@ import { type Context } from '../context';
|
||||
import { getUpdateInfo } from '../helpers/logging';
|
||||
import { type ErrorHandler } from 'grammy';
|
||||
|
||||
export const errorHandler: ErrorHandler<Context> = (error) => {
|
||||
export const errorHandler: ErrorHandler<Context> = async (error) => {
|
||||
const { ctx } = error;
|
||||
|
||||
await ctx.reply(ctx.t('err-generic'));
|
||||
|
||||
ctx.logger.error({
|
||||
err: error.error,
|
||||
update: getUpdateInfo(ctx),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user