Skip to content

Commit 611971d

Browse files
handle async errors thrown after promise.resolve
1 parent cbb67a9 commit 611971d

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

bot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const privateChat = composer.chatType("private");
2121
const wrapper =
2222
(handler: (ctx: BotContext) => Promise<void>) =>
2323
async (ctx: BotContext) => {
24-
handler(ctx).catch((err) => {
24+
handler(ctx).catch(async (err: any) => {
2525
console.error(`Error in ${handler.name}: ${err}`);
2626
if (!ctx.chosenInlineResult) {
2727
try {
28-
ctx.reply("An error has occurred. Please try again later. If this issue persists, please contact the bot developer.");
28+
await ctx.reply("An error has occurred. Please try again later. If this issue persists, please contact the bot developer.");
2929
} catch (error: any) {
3030
console.error(
3131
`Error in ${handler.name}: Cannot send error feedback to user (${error.message}) `

constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const INVALID_PROVIDER_TEXT = "Invalid provider: ";
1717
export const TRACK_NOT_AVAILABLE_TEXT =
1818
"Track is still being processed. Please try again later.";
1919
export const TRACK_NOT_AVAILABLE_MESSAGE =
20-
"This track will be added within 15 minutes.";
20+
"This track will be added within 5 minutes.";
2121
export const SEARCH_HELP_TEXT =
2222
"You can search for tracks, albums and playlists.\n\nTrack search example:\n<pre>search (track name)</pre><pre>search track (track name)</pre>\nAlbum search example:\n<pre>search album (album name)</pre>\nPlaylist search example:\n<pre>search playlist (playlist name)</pre>\n\nThe search query is case-insensitive so you don't have to worry about captial and small letters. You can also search for tracks in inline mode.";
2323
export const CHECK_AGAIN_TEXT = "Check Again";

handlers/callback_query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export default async function callback_query_handler(ctx: BotContext) {
3535
} else if (suffix === "album") {
3636
await spotifyAlbumHandler(ctx, id, { message: ctx.msg });
3737
} else if (suffix === "album-dl") {
38-
spotifyAlbumHandler(ctx, id, { message: ctx.msg, upload: true });
38+
await spotifyAlbumHandler(ctx, id, { message: ctx.msg, upload: true });
3939
} else if (suffix === "playlist") {
4040
await spotifyPlaylistHandler(ctx, id, { message: ctx.msg });
4141
} else if (suffix === "playlist-dl") {
42-
spotifyPlaylistHandler(ctx, id, { message: ctx.msg, upload: true });
42+
await spotifyPlaylistHandler(ctx, id, { message: ctx.msg, upload: true });
4343
} else {
4444
await ctx.answerCallbackQuery({
4545
text: INVALID_PROVIDER_TEXT + suffix,

modules/methods/replyWithMutlipleSongs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@ export default async function replyWithMutlipleSongs(
2929
disable_notification: others?.disable_notification ?? true,
3030
});
3131
}
32-
33-
await new Promise((resolve) => setTimeout(resolve, 1000));
3432
}
3533
}

modules/methods/replyWithSong.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default async function replyWithSong(
5656
disable_notification,
5757
});
5858
} else {
59-
console.error(error);
59+
throw error;
6060
}
6161
} finally {
6262
if (message) {

0 commit comments

Comments
 (0)