From 0a81acfa5c7a7525ab407ae2f5c84338f4c4ab8d Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 4 Feb 2021 21:34:11 -0500 Subject: [PATCH] Even better error handling --- copyvios/api.py | 4 ++-- copyvios/checker.py | 8 ++++---- templates/index.mako | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/copyvios/api.py b/copyvios/api.py index 4da06fd..703a0cb 100644 --- a/copyvios/api.py +++ b/copyvios/api.py @@ -75,10 +75,10 @@ def _hook_check(query): return format_api_error("bad_site", info) elif not query.result: if query.oldid: - info = u"The given revision ID doesn't seem to exist: {0}" + info = u"The revision ID couldn't be found: {0}" return format_api_error("bad_oldid", info.format(query.oldid)) else: - info = u"The given page doesn't seem to exist: {0}" + info = u"The page couldn't be found: {0}" return format_api_error("bad_title", info.format(query.page.title)) result = query.result diff --git a/copyvios/checker.py b/copyvios/checker.py index 71c73a1..22b1a02 100644 --- a/copyvios/checker.py +++ b/copyvios/checker.py @@ -105,17 +105,17 @@ def _get_results(query, follow=True): query.error = "bad action" def _get_page_by_revid(site, revid): - res = site.api_query(action="query", prop="info|revisions", revids=revid, - rvprop="content|timestamp", inprop="protection|url", - rvslots="main") try: + res = site.api_query(action="query", prop="info|revisions", revids=revid, + rvprop="content|timestamp", inprop="protection|url", + rvslots="main") page_data = res["query"]["pages"].values()[0] title = page_data["title"] # Only need to check that these exist: revision = page_data["revisions"][0] revision["slots"]["main"]["*"] revision["timestamp"] - except (KeyError, IndexError): + except (exceptions.APIError, KeyError, IndexError): return None page = site.get_page(title) diff --git a/templates/index.mako b/templates/index.mako index 44586c8..cbee23d 100644 --- a/templates/index.mako +++ b/templates/index.mako @@ -41,11 +41,11 @@ % elif query.oldid and not result:
-

The given revision ID doesn't seem to exist: ${query.oldid | h}.

+

The revision ID couldn't be found: ${query.oldid | h}.

% elif query.title and not result:
-

The given page doesn't seem to exist: ${query.page.title | h}.

+

The page couldn't be found: ${query.page.title | h}.

% endif %endif