Skip to content

Commit f8414ae

Browse files
committed
catch errors
1 parent aa2a965 commit f8414ae

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

app/services/discord/modules/webhook-handler.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,35 @@ export default async (bot: DiscordBot): Promise<void> => {
201201
/https?:\/\/github\.com\/(?<owner>\S+)\/(?<repo>\S+)\/(?<sha>\S+)/.exec(
202202
url ?? ""
203203
) || [];
204-
205-
const res = await (
206-
await bot.container.getService("Github")
207-
).octokit.rest.repos.getCommit({ owner, repo, ref });
208-
files = res.data.files?.flatMap(f => f.filename);
204+
try {
205+
const res = await (
206+
await bot.container.getService("Github")
207+
).octokit.rest.repos.getCommit({ owner, repo, ref });
208+
files = res.data.files?.flatMap(f => f.filename);
209+
} catch (err) {
210+
await ctx.reply(
211+
"something went wrong fetching the files from github :( ... aborting"
212+
);
213+
console.error(err);
214+
return;
215+
}
209216
} else if (url.startsWith("https://gitlab.com")) {
210217
const [, id, sha] =
211218
/https?:\/\/gitlab\.com\/(?<id>\S+)\/-\/commit\/(?<sha>\S+)/.exec(
212219
url ?? ""
213220
) || [];
214-
const res = await (
215-
await bot.container.getService("Gitlab")
216-
).api.Commits.showDiff(encodeURIComponent(id), sha);
217-
files = res.filter(f => !f.deleted_file).flatMap(f => f.new_path);
221+
try {
222+
const res = await (
223+
await bot.container.getService("Gitlab")
224+
).api.Commits.showDiff(encodeURIComponent(id), sha);
225+
files = res.filter(f => !f.deleted_file).flatMap(f => f.new_path);
226+
} catch (err) {
227+
await ctx.reply(
228+
"something went wrong fetching the files from gitlab :( ... aborting"
229+
);
230+
console.error(err);
231+
return;
232+
}
218233
}
219234

220235
if (!files || files.length === 0) {

0 commit comments

Comments
 (0)