mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #257 from YunoHost/return-additional-error-data-to-api
Support more complex errors (be able to return additional data in a json structure)
This commit is contained in:
commit
ae4087d522
2 changed files with 14 additions and 3 deletions
|
@ -377,6 +377,9 @@ class MoulinetteError(Exception):
|
|||
super(MoulinetteError, self).__init__(msg)
|
||||
self.strerror = msg
|
||||
|
||||
def content(self):
|
||||
return self.strerror
|
||||
|
||||
|
||||
class MoulinetteLdapIsDownError(MoulinetteError):
|
||||
"""Used when ldap is down"""
|
||||
|
|
|
@ -484,7 +484,7 @@ class _ActionsMapPlugin(object):
|
|||
try:
|
||||
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
||||
except MoulinetteError as e:
|
||||
raise HTTPBadRequestResponse(e.strerror)
|
||||
raise HTTPBadRequestResponse(e)
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPResponse):
|
||||
raise e
|
||||
|
@ -553,8 +553,16 @@ class HTTPOKResponse(HTTPResponse):
|
|||
|
||||
|
||||
class HTTPBadRequestResponse(HTTPResponse):
|
||||
def __init__(self, output=""):
|
||||
super(HTTPBadRequestResponse, self).__init__(output, 400)
|
||||
def __init__(self, error=""):
|
||||
|
||||
if isinstance(error, MoulinetteError):
|
||||
content = error.content()
|
||||
if isinstance(content, dict):
|
||||
super(HTTPBadRequestResponse, self).__init__(json_encode(content), 400, headers={'Content-type': 'application/json'})
|
||||
else:
|
||||
super(HTTPBadRequestResponse, self).__init__(content, 400)
|
||||
else:
|
||||
super(HTTPBadRequestResponse, self).__init__(error, 400)
|
||||
|
||||
|
||||
class HTTPUnauthorizedResponse(HTTPResponse):
|
||||
|
|
Loading…
Add table
Reference in a new issue