mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Get rid of error_to_response and trigger 400 error for all MoulinetteErrors instead
This commit is contained in:
parent
fddf64a20d
commit
8e91c0d0d3
1 changed files with 2 additions and 28 deletions
|
@ -347,7 +347,7 @@ class _ActionsMapPlugin(object):
|
||||||
self.logout(profile)
|
self.logout(profile)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
raise error_to_response(e)
|
raise HTTPUnauthorizedResponse(e.strerror)
|
||||||
else:
|
else:
|
||||||
# Update dicts with new values
|
# Update dicts with new values
|
||||||
s_hashes[profile] = s_hash
|
s_hashes[profile] = s_hash
|
||||||
|
@ -434,7 +434,7 @@ class _ActionsMapPlugin(object):
|
||||||
try:
|
try:
|
||||||
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
raise error_to_response(e)
|
raise HTTPBadRequestResponse(e.strerror)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, HTTPResponse):
|
if isinstance(e, HTTPResponse):
|
||||||
raise e
|
raise e
|
||||||
|
@ -518,38 +518,12 @@ class HTTPUnauthorizedResponse(HTTPResponse):
|
||||||
super(HTTPUnauthorizedResponse, self).__init__(output, 401)
|
super(HTTPUnauthorizedResponse, self).__init__(output, 401)
|
||||||
|
|
||||||
|
|
||||||
class HTTPForbiddenResponse(HTTPResponse):
|
|
||||||
|
|
||||||
def __init__(self, output=''):
|
|
||||||
super(HTTPForbiddenResponse, self).__init__(output, 403)
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPErrorResponse(HTTPResponse):
|
class HTTPErrorResponse(HTTPResponse):
|
||||||
|
|
||||||
def __init__(self, output=''):
|
def __init__(self, output=''):
|
||||||
super(HTTPErrorResponse, self).__init__(output, 500)
|
super(HTTPErrorResponse, self).__init__(output, 500)
|
||||||
|
|
||||||
|
|
||||||
def error_to_response(error):
|
|
||||||
"""Convert a MoulinetteError to relevant HTTP response."""
|
|
||||||
if error.errno == errno.EPERM:
|
|
||||||
return HTTPForbiddenResponse(error.strerror)
|
|
||||||
elif error.errno == errno.EACCES:
|
|
||||||
return HTTPUnauthorizedResponse(error.strerror)
|
|
||||||
# Client-side error
|
|
||||||
elif error.errno in [errno.ENOENT, errno.ESRCH, errno.ENXIO, errno.EEXIST,
|
|
||||||
errno.ENODEV, errno.EINVAL, errno.ENOPKG, errno.EDESTADDRREQ]:
|
|
||||||
return HTTPBadRequestResponse(error.strerror)
|
|
||||||
# Server-side error
|
|
||||||
elif error.errno in [errno.EIO, errno.EBUSY, errno.ENODATA, errno.EINTR,
|
|
||||||
errno.ENETUNREACH]:
|
|
||||||
return HTTPErrorResponse(error.strerror)
|
|
||||||
else:
|
|
||||||
logger.debug('unknown relevant response for error [%s] %s',
|
|
||||||
error.errno, error.strerror)
|
|
||||||
return HTTPErrorResponse(error.strerror)
|
|
||||||
|
|
||||||
|
|
||||||
def format_for_response(content):
|
def format_for_response(content):
|
||||||
"""Format the resulted content of a request for the HTTP response."""
|
"""Format the resulted content of a request for the HTTP response."""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|
Loading…
Add table
Reference in a new issue