From 1e5849f5040f1bac4e9a41c59488f2457593f90c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 3 Jun 2021 11:29:55 -0400 Subject: [PATCH] Prevent failing on api errors --- src/routes/postSkipSegments.ts | 2 +- src/routes/voteOnSponsorTime.ts | 7 ++----- src/utils/youtubeApi.ts | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index bae0692..3da291a 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -212,7 +212,7 @@ async function autoModerateSubmission(apiVideoInfo: APIVideoInfo, return a[0] - b[0] || a[1] - b[1]; })); - const videoDuration = data.lengthSeconds; + const videoDuration = data?.lengthSeconds; if (videoDuration != 0) { let allSegmentDuration = 0; //sum all segment times together diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 2ae0a4c..0e37732 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -59,11 +59,8 @@ async function sendWebhooks(voteData: VoteData) { if (config.newLeafURL !== null) { const { err, data } = await YouTubeAPI.listVideos(submissionInfoRow.videoID); - - if (err) { - Logger.error(err.toString()); - return; - } + if (err) return; + const isUpvote = voteData.incrementAmount > 0; // Send custom webhooks dispatchEvent(isUpvote ? "vote.up" : "vote.down", { diff --git a/src/utils/youtubeApi.ts b/src/utils/youtubeApi.ts index 95ef422..855a2d6 100644 --- a/src/utils/youtubeApi.ts +++ b/src/utils/youtubeApi.ts @@ -29,7 +29,8 @@ export class YouTubeAPI { if (result.ok) { const data = await result.json(); if (data.error) { - return { err: data.err, data: null }; + Logger.warn("CloudTube API Error: " + data.error) + return { err: data.error, data: null }; } redis.setAsync(redisKey, JSON.stringify(data)).then((result) => {