Catch save errors and report to admin.

This commit is contained in:
Edward Betts 2020-04-22 16:45:59 +01:00
parent 6194874380
commit fce288dcee

8
app.py
View file

@ -2,7 +2,7 @@
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) wd_catalog, human, wikibase, wikidata_oauth, wikidata_edit, mail)
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)
@ -15,6 +15,7 @@ from sqlalchemy.orm import aliased
from sqlalchemy.sql.expression import desc from sqlalchemy.sql.expression import desc
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime
import simplejson.errors
import requests.exceptions import requests.exceptions
import inspect import inspect
import itertools import itertools
@ -174,7 +175,12 @@ def save(item_id):
continue continue
r = create_claim(item_id, depicts_id, token) r = create_claim(item_id, depicts_id, token)
try:
reply = r.json() reply = r.json()
except simplejson.errors.JSONDecodeError:
mail.send_mail('depicts save error', r.text)
raise
if 'error' in reply: if 'error' in reply:
return 'error:' + r.text return 'error:' + r.text
saved = r.json() saved = r.json()