Skip to content
Snippets Groups Projects
Commit 9b7bf2e5 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Custom error handler for 400 Bad Request

parent dbf97e21
No related branches found
No related tags found
1 merge request!4CLI tool to upload files and start imports
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment