Proper display of save errors.

This commit is contained in:
Edward Betts 2020-04-22 17:11:23 +01:00
parent fce288dcee
commit 97e4501427
3 changed files with 33 additions and 3 deletions

15
app.py
View file

@ -2,7 +2,8 @@
from flask import Flask, render_template, url_for, redirect, request, g, jsonify, session from flask import Flask, render_template, url_for, redirect, request, g, jsonify, session
from depicts import (utils, wdqs, commons, mediawiki, artwork, database, from depicts import (utils, wdqs, commons, mediawiki, artwork, database,
wd_catalog, human, wikibase, wikidata_oauth, wikidata_edit, mail) wd_catalog, human, wikibase, wikidata_oauth, wikidata_edit, mail,
fixtures)
from depicts.pager import Pagination, init_pager from depicts.pager import Pagination, init_pager
from depicts.model import (DepictsItem, DepictsItemAltLabel, Edit, Item, from depicts.model import (DepictsItem, DepictsItemAltLabel, Edit, Item,
Language, WikidataQuery, Triple) Language, WikidataQuery, Triple)
@ -181,8 +182,11 @@ def save(item_id):
mail.send_mail('depicts save error', r.text) mail.send_mail('depicts save error', r.text)
raise raise
if 'error' in reply: save_error = reply.get('error')
return 'error:' + r.text if save_error:
mail.send_mail('depicts save error', r.text)
return render_template('save_error.html', error=save_error)
saved = r.json() saved = r.json()
lastrevid = saved['pageinfo']['lastrevid'] lastrevid = saved['pageinfo']['lastrevid']
assert saved['success'] == 1 assert saved['success'] == 1
@ -1090,6 +1094,11 @@ def server_block_report():
check_for_blocks() check_for_blocks()
return render_template('block_report.html') return render_template('block_report.html')
@app.route('/fixture/save_error')
def save_error_fixture():
error = fixtures.save_error()['error']
return render_template('save_error.html', error=error)
if __name__ == "__main__": if __name__ == "__main__":
app.debug = True app.debug = True

3
depicts/fixtures.py Normal file
View file

@ -0,0 +1,3 @@
def save_error():
return {"error":{"code":"failed-save","info":"The save has failed.","messages":[{"name":"wikibase-api-failed-save","parameters":[],"html":"The save has failed."},{"name":"wikimedia-globalblocking-ipblocked-range","parameters":["[//meta.wikimedia.org/wiki/User:Jon_Kolbert Jon Kolbert]","meta.wikimedia.org","[[m:NOP|Open Proxy]]: Colocation webhost, Contact [[m:Special:Contact/stewards|stewards]] if you are affected","04:21, 8 April 2020","04:21, 8 April 2023","78.129.222.14","78.129.128.0/17"],"html":"<p><b>Your IP address is in a range that has been <a href=\"https://meta.wikimedia.org/wiki/Special:MyLanguage/Global_blocks\" class=\"extiw\" title=\"m:Special:MyLanguage/Global blocks\">blocked on all Wikimedia Foundation wikis</a>.</b>\n</p><p>The block was made by <a class=\"external text\" href=\"https://meta.wikimedia.org/wiki/User:Jon_Kolbert\">Jon Kolbert</a> (meta.wikimedia.org).\nThe reason given is <i><a href=\"https://meta.wikimedia.org/wiki/NOP\" class=\"extiw\" title=\"m:NOP\">Open Proxy</a>: Colocation webhost, Contact <a href=\"https://meta.wikimedia.org/wiki/Special:Contact/stewards\" class=\"extiw\" title=\"m:Special:Contact/stewards\">stewards</a> if you are affected</i>.\n</p>\n<ul><li>Start of block: 04:21, 8 April 2020</li>\n<li>Expiry of block: 04:21, 8 April 2023</li></ul>\n<p>Your current IP address is 78.129.222.14 and the blocked range is 78.129.128.0/17.\nPlease include all above details in any queries you make.\n</p><p>If you believe you were blocked by mistake, you can find additional information and instructions in the <a href=\"https://meta.wikimedia.org/wiki/Special:MyLanguage/No_open_proxies\" class=\"extiw\" title=\"m:Special:MyLanguage/No open proxies\">No open proxies</a> global policy.\nOtherwise, to discuss the block please <a href=\"https://meta.wikimedia.org/wiki/Steward_requests/Global\" class=\"extiw\" title=\"m:Steward requests/Global\">post a request for review on Meta-Wiki</a> or send an email to the <a href=\"https://meta.wikimedia.org/wiki/Special:MyLanguage/Stewards\" class=\"extiw\" title=\"m:Special:MyLanguage/Stewards\">stewards</a> <a href=\"https://meta.wikimedia.org/wiki/Special:MyLanguage/OTRS\" class=\"extiw\" title=\"m:Special:MyLanguage/OTRS\">OTRS</a> queue at <kbd>stewards@wikimedia.org</kbd> including all above details.\n</p>"},{"name":"permissionserrors","parameters":[],"html":"Permission error"}],"docref":"See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes."},"servedby":"mw1315"}

18
templates/save_error.html Normal file
View file

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block content %}
<div class="p-2">
<h1>Error saving depicts statements to Wikidata</h1>
<p>It was not possible to save your edit to Wikidata. The details of the error returned by the Wikidata API are below.</p>
{% for message in error.messages %}
<h4>{{ message.name }}</h4>
<div class="mb-3">
{{ message.html | safe }}
</div>
{% endfor %}
</div>
{% endblock %}