Skip to content

Commit

Permalink
Add support to handle failure in fetching title from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Mar 17, 2023
1 parent 4938203 commit 0f95d9a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default {
confirmText: "",
titleUrl: `${process.env.VUE_APP_API_URL}/metadata/title-from-url`,
songNameExtracted: null,
isTitleLoading: false
isTitleLoading: false,
isTitleLoadFailed: false
};
},
methods: {
Expand All @@ -71,7 +72,11 @@ export default {
this.songNameExtracted = await this.extractTitleFromUrl(
searchData.youtubeUrl
);
this.isTitleLoading = false;
// Check if title load failed
if (this.isTitleLoadFailed) return;
}
// Check if we need to show the prompt. If we do, show the prompt,
Expand Down Expand Up @@ -122,6 +127,13 @@ export default {
method: "GET"
}
);
// Handle the case if the response is not 200 OK
if (response.status != 200) {
this.isTitleLoadFailed = true;
return "";
}
const jsonData = await response.json();
// TODO: Do something with the should_verify flag
Expand All @@ -139,6 +151,8 @@ export default {
getNoQueryText() {
return this.isTitleLoading
? "Extracting title from the entered URL..."
: this.isTitleLoadFailed
? "Failed to load details for the entered URL. Please try with a different URL"
: "You need to enter the name of a song";
}
},
Expand Down

0 comments on commit 0f95d9a

Please sign in to comment.