summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-10-23 20:58:07 -0500
committerOmar Roth <omarroth@hotmail.com>2018-10-23 20:58:07 -0500
commitceff2763a580f1af47227d75fadab1f7162efedb (patch)
tree0170f7e3b050aba887405cdf638305a32e4a9e19 /src
parent8fd54027de246d39543f99548c964ca09a92ce92 (diff)
downloadinvidious-ceff2763a580f1af47227d75fadab1f7162efedb.tar.gz
invidious-ceff2763a580f1af47227d75fadab1f7162efedb.tar.bz2
invidious-ceff2763a580f1af47227d75fadab1f7162efedb.zip
Update error messages for /api/v1/channels
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr20
-rw-r--r--src/invidious/channels.cr11
2 files changed, 17 insertions, 14 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 33ce260e..1a8153e4 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -1482,8 +1482,8 @@ get "/feed/channel/:ucid" do |env|
begin
author, ucid, auto_generated = get_about_info(ucid)
rescue ex
- error_message = "User does not exist"
- halt env, status_code: 404, response: error_message
+ error_message = ex.message
+ halt env, status_code: 500, response: error_message
end
page = 1
@@ -1720,7 +1720,7 @@ get "/channel/:ucid" do |env|
begin
author, ucid, auto_generated, sub_count = get_about_info(ucid)
rescue ex
- error_message = "User does not exist"
+ error_message = ex.message
next templated "error"
end
@@ -1763,7 +1763,7 @@ get "/api/v1/captions/:id" do |env|
rescue ex : VideoRedirect
next env.redirect "/api/v1/captions/#{ex.message}"
rescue ex
- halt env, status_code: 403
+ halt env, status_code: 500
end
captions = video.captions
@@ -1955,7 +1955,7 @@ get "/api/v1/comments/:id" do |env|
response = JSON.parse(response.body)
if !response["response"]["continuationContents"]?
- halt env, status_code: 403
+ halt env, status_code: 500
end
response = response["response"]["continuationContents"]
@@ -2486,8 +2486,8 @@ get "/api/v1/channels/:ucid" do |env|
begin
author, ucid, auto_generated = get_about_info(ucid)
rescue ex
- error_message = {"error" => "User does not exist"}.to_json
- halt env, status_code: 404, response: error_message
+ error_message = {"error" => ex.message}.to_json
+ halt env, status_code: 500, response: error_message
end
page = 1
@@ -2627,8 +2627,8 @@ end
begin
author, ucid, auto_generated = get_about_info(ucid)
rescue ex
- error_message = {"error" => "User does not exist"}.to_json
- halt env, status_code: 404, response: error_message
+ error_message = {"error" => ex.message}.to_json
+ halt env, status_code: 500, response: error_message
end
videos, count = get_60_videos(ucid, page, auto_generated)
@@ -2913,7 +2913,7 @@ get "/api/v1/playlists/:plid" do |env|
playlist = fetch_playlist(plid)
rescue ex
error_message = {"error" => "Playlist is empty"}.to_json
- halt env, status_code: 404, response: error_message
+ halt env, status_code: 500, response: error_message
end
begin
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index 5647dbc5..3a894b66 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -189,16 +189,19 @@ end
def get_about_info(ucid)
client = make_client(YT_URL)
- about = client.get("/user/#{ucid}/about?disable_polymer=1&gl=US&hl=en")
+ about = client.get("/channel/#{ucid}/about?disable_polymer=1&gl=US&hl=en")
about = XML.parse_html(about.body)
if !about.xpath_node(%q(//span[contains(@class,"qualified-channel-title-text")]/a))
- about = client.get("/channel/#{ucid}/about?disable_polymer=1&gl=US&hl=en")
+ about = client.get("/user/#{ucid}/about?disable_polymer=1&gl=US&hl=en")
about = XML.parse_html(about.body)
end
- if !about.xpath_node(%q(//span[contains(@class,"qualified-channel-title-text")]/a))
- raise "User does not exist."
+ if about.xpath_node(%q(//span[contains(@class,"qualified-channel-title-text")]/a)).try &.content.empty?
+ error_message = about.xpath_node(%q(//div[@class="yt-alert-content"])).try &.content.strip
+ error_message ||= "Could not get channel info."
+
+ raise error_message
end
sub_count = about.xpath_node(%q(//span[contains(text(), "subscribers")]))