diff --git a/arkindex/client.py b/arkindex/client.py index a969dbfe4f0b37b2ce7c98b920673d7aedcd9a0e..6297545b8adb398418bda798f5b31d441c93cf56 100644 --- a/arkindex/client.py +++ b/arkindex/client.py @@ -25,17 +25,33 @@ class ArkindexAPI(object): response.raise_for_status() return response.json() - def post(self, endpoint, params=None, json=None, requires_auth=False): + def post(self, endpoint, params=None, json=None, files=None, requires_auth=False): response = requests.post( urljoin(self.base_url, endpoint), params=params, json=json, + files=files, auth=self._get_auth(requires_auth), verify=self.verify_ssl, ) + if response.status_code == 400: + try: + self.bad_request_handler(response.json()) + except ArkindexAPIError: + # Ignore everything but Arkindex exceptions from the custom handler + raise + except: + pass response.raise_for_status() return response.json() + def bad_request_handler(self, json): + if isinstance(json, list): + raise ArkindexAPIError(' - '.join(json)) + elif isinstance(json, dict) and 'detail' in json: + raise ArkindexAPIError(json['detail']) + raise ArkindexAPIError(json) + def login(self, email, password): ''' Login on an Arkindex server with email+password