diff options
| author | rr- | 2016-09-10 10:14:40 +0200 |
|---|---|---|
| committer | rr- | 2016-09-10 10:16:14 +0200 |
| commit | 0a19e7bbd08c70b2728b127570cd032a00e8d244 (patch) | |
| tree | 6b7f2d9c7631a08482cae004daaae18baf3fc08c /server/szurubooru/rest | |
| parent | c516030c66cf7cece87bdca49da0e21c427fcb71 (diff) | |
server/errors: allow extra info in errors
Diffstat (limited to 'server/szurubooru/rest')
| -rw-r--r-- | server/szurubooru/rest/app.py | 7 | ||||
| -rw-r--r-- | server/szurubooru/rest/errors.py | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/server/szurubooru/rest/app.py b/server/szurubooru/rest/app.py index 199d098..da8f2dd 100644 --- a/server/szurubooru/rest/app.py +++ b/server/szurubooru/rest/app.py @@ -102,7 +102,10 @@ def application(env, start_response): start_response( '%d %s' % (ex.code, ex.reason), [('content-type', 'application/json')]) - return (_dump_json({ + blob = { 'title': ex.title, 'description': ex.description, - }).encode('utf-8'),) + } + for key, value in ex.extra_fields.items(): + blob[key] = value + return (_dump_json(blob).encode('utf-8'),) diff --git a/server/szurubooru/rest/errors.py b/server/szurubooru/rest/errors.py index f9755a7..0189147 100644 --- a/server/szurubooru/rest/errors.py +++ b/server/szurubooru/rest/errors.py @@ -5,10 +5,11 @@ class BaseHttpError(RuntimeError): code = None reason = None - def __init__(self, description, title=None): + def __init__(self, description, title=None, extra_fields=None): super().__init__() self.description = description self.title = title or self.reason + self.extra_fields = extra_fields class HttpBadRequest(BaseHttpError): |