Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions erclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,13 @@ async def _post(self, path, payload, params=None):
async def _patch(self, path, payload, params=None):
return await self._call(path, payload, "PATCH", params)

async def _call(self, path, payload, method, params=None):
async def _delete(self, path, params=None, base_url=None):
"""Perform an async DELETE request. Delegates to _call (204/no body handled there)."""
return await self._call(
path=path, payload=None, method="DELETE", params=params, base_url=base_url
)

async def _call(self, path, payload, method, params=None, base_url=None):
try:
auth_headers = await self.auth_headers()
except httpx.HTTPStatusError as e:
Expand All @@ -1444,10 +1450,15 @@ async def _call(self, path, payload, method, params=None):
'User-Agent': self.user_agent,
**auth_headers
}
request_url = (
f"{base_url.rstrip('/')}/{path.lstrip('/')}"
if base_url is not None
else self._er_url(path)
)
try:
response = await self._http_session.request(
method,
self._er_url(path),
request_url,
# payload is automatically encoded as json data
json=payload if method in [
"POST", "PUT", "PATCH"] else None,
Expand All @@ -1468,7 +1479,9 @@ async def _call(self, path, payload, method, params=None):
raise ERClientException(f'Request to ER failed: {reason}')
except httpx.HTTPStatusError as e:
self._handle_http_status_error(path, method, e)
else: # Parse the response
else: # Parse the response (204 No Content has no body)
if response.status_code == httpx.codes.NO_CONTENT:
return True # DELETE/empty success
json_response = response.json()
return json_response.get('data', json_response)

Expand Down