Added HTTP error check.
This commit is contained in:
5
main.py
5
main.py
@@ -1,6 +1,6 @@
|
||||
import argparse
|
||||
import praw
|
||||
from requests.exceptions import ConnectionError
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
|
||||
from rtv.errors import SubmissionURLError, SubredditNameError
|
||||
from rtv.utils import curses_session
|
||||
@@ -40,6 +40,9 @@ def main():
|
||||
except ConnectionError:
|
||||
print('Timeout: Could not connect to website')
|
||||
|
||||
except HTTPError:
|
||||
print('HTTP Error: 404 Not Found')
|
||||
|
||||
except SubmissionURLError as e:
|
||||
print('Could not reach submission URL: {}'.format(e.url))
|
||||
|
||||
|
||||
@@ -136,11 +136,14 @@ class BasePage(object):
|
||||
self._header_window = self.stdscr.derwin(1, n_cols, 0, 0)
|
||||
self._content_window = self.stdscr.derwin(1, 0)
|
||||
|
||||
self.stdscr.erase()
|
||||
self._draw_header()
|
||||
self._draw_content()
|
||||
|
||||
self.add_cursor()
|
||||
|
||||
def draw_item(self, window, data, inverted):
|
||||
@staticmethod
|
||||
def draw_item(window, data, inverted):
|
||||
raise NotImplementedError
|
||||
|
||||
def _draw_header(self):
|
||||
@@ -149,7 +152,8 @@ class BasePage(object):
|
||||
|
||||
self._header_window.erase()
|
||||
attr = curses.A_REVERSE | curses.A_BOLD | Color.CYAN
|
||||
self._header_window.addnstr(0, 0, self.content.name, n_cols-1, attr)
|
||||
self._header_window.bkgd(' ', attr)
|
||||
self._header_window.addnstr(0, 0, self.content.name, n_cols-1)
|
||||
self._header_window.refresh()
|
||||
|
||||
def _draw_content(self):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import curses
|
||||
import sys
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
from .errors import SubredditNameError
|
||||
from .page import BasePage
|
||||
@@ -63,7 +64,7 @@ class SubredditPage(BasePage):
|
||||
self.content = SubredditContent.from_name(
|
||||
self.reddit, name, self.loader)
|
||||
|
||||
except SubredditNameError:
|
||||
except (SubredditNameError, HTTPError):
|
||||
display_message(self.stdscr, 'Invalid Subreddit')
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user