Commit c0870211 authored by Titouan Soulard's avatar Titouan Soulard

erp5_api_style: report BadRequest errors in JSON

parent 414b87c5
...@@ -51,19 +51,33 @@ def convertTojIOAPICall(function): ...@@ -51,19 +51,33 @@ def convertTojIOAPICall(function):
except Unauthorized, e: except Unauthorized, e:
LOG('jIOWebSection', INFO, 'Converting Unauthorized to Unauthorized error mesage in JSON,', LOG('jIOWebSection', INFO, 'Converting Unauthorized to Unauthorized error mesage in JSON,',
error=True) error=True)
return self.ERP5Site_logApiErrorAndReturn( body = self.ERP5Site_logApiErrorAndReturn(
error_code="403", error_code="403",
error_message=str(e), error_message=str(e),
error_name="Unauthorized" error_name="Unauthorized"
) )
self.REQUEST.response.setBody(body, lock=True)
raise
except NotFound, e: except NotFound, e:
LOG('jIOWebSection', INFO, 'Converting NotFound to NotFound error mesage in JSON,', LOG('jIOWebSection', INFO, 'Converting NotFound to NotFound error mesage in JSON,',
error=True) error=True)
return self.ERP5Site_logApiErrorAndReturn( body = self.ERP5Site_logApiErrorAndReturn(
error_code="404", error_code="404",
error_message=str(e), error_message=str(e),
error_name="NotFound" error_name="NotFound"
) )
self.REQUEST.response.setBody(body, lock=True)
raise
except:
LOG('jIOWebSection', INFO, 'Converting Error to InternalError message in JSON,',
error=True)
body = self.ERP5Site_logApiErrorAndReturn(
error_code="500",
error_message="Internal Server Error",
error_name="InternalError"
)
self.REQUEST.response.setBody(body, lock=True)
raise
return '%s' % retval return '%s' % retval
wrapper.__doc__ = function.__doc__ wrapper.__doc__ = function.__doc__
......
...@@ -7,7 +7,7 @@ error = context.getPortalObject().error_record_module.newContent( ...@@ -7,7 +7,7 @@ error = context.getPortalObject().error_record_module.newContent(
description=str(error_message), description=str(error_message),
text_content=str(text_content) text_content=str(text_content)
) )
container.REQUEST.RESPONSE.setStatus(400) container.REQUEST.RESPONSE.setStatus(error_code, lock=True)
# We follow here Paypal api guideline # We follow here Paypal api guideline
# https://github.com/paypal/api-standards/blob/master/api-style-guide.md#error-schema # https://github.com/paypal/api-standards/blob/master/api-style-guide.md#error-schema
error_dict = { error_dict = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment