Added HTTP error check.

This commit is contained in:
Michael Lazar
2015-02-11 22:35:04 -08:00
parent 1b8b25fd8b
commit d018b6fd42
3 changed files with 12 additions and 4 deletions

View File

@@ -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))

View File

@@ -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):

View File

@@ -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: