Browse Source

Even better error handling

master
Ben Kurtovic 3 years ago
parent
commit
0a81acfa5c
3 changed files with 8 additions and 8 deletions
  1. +2
    -2
      copyvios/api.py
  2. +4
    -4
      copyvios/checker.py
  3. +2
    -2
      templates/index.mako

+ 2
- 2
copyvios/api.py View File

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


+ 4
- 4
copyvios/checker.py View File

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



+ 2
- 2
templates/index.mako View File

@@ -41,11 +41,11 @@
</div>
% elif query.oldid and not result:
<div id="info-box" class="red-box">
<p>The given revision ID doesn't seem to exist: <a href="https://${query.site.domain | h}/w/index.php?oldid=${query.oldid | h}">${query.oldid | h}</a>.</p>
<p>The revision ID couldn't be found: <a href="https://${query.site.domain | h}/w/index.php?oldid=${query.oldid | h}">${query.oldid | h}</a>.</p>
</div>
% elif query.title and not result:
<div id="info-box" class="red-box">
<p>The given page doesn't seem to exist: <a href="${query.page.url}">${query.page.title | h}</a>.</p>
<p>The page couldn't be found: <a href="${query.page.url}">${query.page.title | h}</a>.</p>
</div>
% endif
%endif


Loading…
Cancel
Save