Commit 7475f107 authored by Titouan Soulard's avatar Titouan Soulard

erp5_jio_connector: properly raise errors for NotFound and BadRequest

parent 46a81380
...@@ -30,6 +30,8 @@ from AccessControl import ClassSecurityInfo ...@@ -30,6 +30,8 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from zExceptions import BadRequest, NotFound
import requests import requests
class JioApiConnector(XMLObject): class JioApiConnector(XMLObject):
...@@ -64,6 +66,13 @@ class JioApiConnector(XMLObject): ...@@ -64,6 +66,13 @@ class JioApiConnector(XMLObject):
except: except:
raise Exception("Error when sending to API ({}): API returned invalid JSON".format(r.status_code)) raise Exception("Error when sending to API ({}): API returned invalid JSON".format(r.status_code))
if r.status_code == 400:
err = BadRequest(result["name"])
err.detail = result["message"]
raise err
if r.status_code == 404:
raise NotFound(result["message"])
raise Exception("Error when sending to API ({}): {}".format(r.status_code, result["message"])) raise Exception("Error when sending to API ({}): {}".format(r.status_code, result["message"]))
def getFromApi(self, request_dict): def getFromApi(self, request_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