Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Studio: Handle Net errors better #7586

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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