Correctly handle case where channel doesn't exist
This commit is contained in:
parent
9d1c688310
commit
a8d74ba082
11
http_errors.py
Normal file
11
http_errors.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class Error4xx(Exception):
|
||||||
|
pass
|
||||||
|
class Error404(Error4xx):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Error5xx(Exception):
|
||||||
|
pass
|
||||||
|
class Error500(Error5xx):
|
||||||
|
pass
|
||||||
|
class Error502(Error5xx):
|
||||||
|
pass
|
@ -4,6 +4,7 @@ import gevent.socket
|
|||||||
|
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
from youtube.youtube import youtube
|
from youtube.youtube import youtube
|
||||||
|
import http_errors
|
||||||
import urllib
|
import urllib
|
||||||
import socket
|
import socket
|
||||||
import socks
|
import socks
|
||||||
@ -114,7 +115,10 @@ def site_dispatch(env, start_response):
|
|||||||
yield error_code('404 Not Found', start_response)
|
yield error_code('404 Not Found', start_response)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
except http_errors.Error404 as e:
|
||||||
|
start_response('404 Not Found', ())
|
||||||
|
yield str(e).encode('utf-8')
|
||||||
|
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
start_response('502 Bad Gateway', ())
|
start_response('502 Bad Gateway', ())
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import youtube.common as common
|
import youtube.common as common
|
||||||
from youtube.common import default_multi_get, URL_ORIGIN, get_thumbnail_url, video_id
|
from youtube.common import default_multi_get, URL_ORIGIN, get_thumbnail_url, video_id
|
||||||
|
import http_errors
|
||||||
import urllib
|
import urllib
|
||||||
import json
|
import json
|
||||||
from string import Template
|
from string import Template
|
||||||
@ -193,6 +194,11 @@ def channel_videos_html(polymer_json, current_page=1, current_sort=3, number_of_
|
|||||||
for alert in response['alerts']:
|
for alert in response['alerts']:
|
||||||
result += alert['alertRenderer']['text']['simpleText'] + '\n'
|
result += alert['alertRenderer']['text']['simpleText'] + '\n'
|
||||||
return result
|
return result
|
||||||
|
elif 'errors' in response['responseContext']:
|
||||||
|
for error in response['responseContext']['errors']['error']:
|
||||||
|
if error['code'] == 'INVALID_VALUE' and error['location'] == 'browse_id':
|
||||||
|
raise http_errors.Error404('This channel does not exist')
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
channel_url = microformat['urlCanonical'].rstrip('/')
|
channel_url = microformat['urlCanonical'].rstrip('/')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user