Skip to content

Commit

Permalink
Studio: Handle Net errors better (#7586)
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 27, 2020
1 parent 99dce89 commit bdad542
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions server/chat-plugins/the-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ export class LastFMInterface {
}
buf += `<br />`;
const trackName = `${track.artist?.['#text'] ? `${track.artist['#text']} - ` : ''}${track.name}`;
const videoIDs = await YouTube.searchVideo(trackName, 1);
let videoIDs: string[] | undefined;
try {
videoIDs = await YouTube.searchVideo(trackName, 1);
} catch (e) {
throw new Chat.ErrorMessage(`Error while fetching video data: ${e.message}`);
}
if (!videoIDs?.length) {
throw new Chat.ErrorMessage(`Something went wrong with the YouTube API.`);
}
Expand Down Expand Up @@ -175,7 +180,12 @@ export class LastFMInterface {
buf += `</td><td>`;
const artistUrl = obj.url.split('_/')[0];
buf += `<strong><a href="${artistUrl}">${artistName}</a> - <a href="${obj.url}">${trackName}</a></strong><br />`;
const videoIDs = await YouTube.searchVideo(searchName, 1);
let videoIDs: string[] | undefined;
try {
videoIDs = await YouTube.searchVideo(searchName, 1);
} catch (e) {
throw new Chat.ErrorMessage(`Error while fetching video data: ${e.message}`);
}
if (!videoIDs?.length) {
buf += searchName;
} else {
Expand Down Expand Up @@ -303,7 +313,12 @@ class RecommendationsInterface {
}

async render(rec: Recommendation, suggested = false) {
const videoInfo = await YouTube.getVideoData(rec.url);
let videoInfo = null;
try {
videoInfo = await YouTube.getVideoData(rec.url);
} catch (e) {
throw new Chat.ErrorMessage(`Error while fetching recommendation URL: ${e.message}`);
}
let buf = ``;
buf += `<div style="color:#000;background:linear-gradient(rgba(210,210,210),rgba(225,225,225))">`;
buf += `<table style="margin:auto;background:rgba(255,255,255,0.25);padding:3px;"><tbody><tr>`;
Expand Down

0 comments on commit bdad542

Please sign in to comment.