refactor abort() calls to use common.error()

pull/27/head
Ryan Barrett 2017-10-15 16:57:33 -07:00
rodzic f940718790
commit 6190f3bc0c
5 zmienionych plików z 11 dodań i 14 usunięć

Wyświetl plik

@ -44,7 +44,7 @@ class ActorHandler(webapp2.RequestHandler):
hcard = mf2util.representative_hcard(mf2, resp.url)
logging.info('Representative h-card: %s', json.dumps(hcard, indent=2))
if not hcard:
self.abort(400, """\
common.error(self, """\
Couldn't find a <a href="http://microformats.org/wiki/representative-hcard-parsing">\
representative h-card</a> on %s""" % resp.url)
@ -76,7 +76,7 @@ class InboxHandler(webapp2.RequestHandler):
except (TypeError, ValueError, AssertionError):
msg = "Couldn't parse body as JSON"
logging.error(msg, exc_info=True)
self.abort(400, msg)
common.error(self, msg)
type = activity.get('type')
if type not in SUPPORTED_TYPES:

Wyświetl plik

@ -19,16 +19,14 @@ class AddWebmentionHandler(webapp2.RequestHandler):
def get(self, url):
url = urllib.unquote(url)
if not url.startswith('http://') and not url.startswith('https://'):
self.abort(400, 'URL must start with http:// or https://')
common.error(self, 'URL must start with http:// or https://')
try:
resp = common.requests_get(url)
except requests.exceptions.Timeout as e:
logging.info('Returning 504 due to', exc_info=True)
self.abort(504, unicode(e))
common.error(self, unicode(e), status=504)
except requests.exceptions.RequestException as e:
logging.info('Returning 502 due to', exc_info=True)
self.abort(502, unicode(e))
common.error(self, unicode(e), status=502)
self.response.status_int = resp.status_code
self.response.write(resp.content)

Wyświetl plik

@ -54,7 +54,7 @@ def _requests_fn(fn, url, parse_json=False, log=False, **kwargs):
def error(handler, msg, status=400):
logging.info(msg)
logging.info('Returning %s: %s' % (status, msg), exc_info=True)
handler.abort(status, msg)

Wyświetl plik

@ -107,9 +107,8 @@ class SlapHandler(webapp2.RequestHandler):
response.put()
if errors:
self.abort(errors[0].get('http_status') or 400,
'Errors:\n' + '\n'.join(json.dumps(e, indent=2) for e in errors))
msg = 'Errors:\n' + '\n'.join(json.dumps(e, indent=2) for e in errors)
common.error(self, msg, status=errors[0].get('http_status'))
app = webapp2.WSGIApplication([
(r'/%s/salmon' % common.ACCT_RE, SlapHandler),

Wyświetl plik

@ -57,7 +57,7 @@ class WebmentionHandler(webapp2.RequestHandler):
if isinstance(target, dict):
target = target.get('url')
if not target:
self.abort(400, 'No u-in-reply-to found in %s' % source_url)
common.error(self, 'No u-in-reply-to found in %s' % source_url)
try:
resp = common.requests_get(target, headers=activitypub.CONNEG_HEADER,
@ -85,7 +85,7 @@ class WebmentionHandler(webapp2.RequestHandler):
inbox_url = actor.get('inbox')
actor = actor.get('url')
if not inbox_url and not actor:
self.abort(400, 'Target object has no actor or attributedTo URL')
common.error(self, 'Target object has no actor or attributedTo URL')
if not inbox_url:
# fetch actor as AS object
@ -96,7 +96,7 @@ class WebmentionHandler(webapp2.RequestHandler):
if not inbox_url:
# TODO: probably need a way to save errors like this so that we can
# return them if ostatus fails too.
# self.abort(400, 'Target actor has no inbox')
# common.error(self, 'Target actor has no inbox')
return self.send_salmon(source_obj, target_url=target_url)
# convert to AS2