From 8d6835b8523a708d802c83372c670599abefba9e Mon Sep 17 00:00:00 2001 From: JoshuaVulcan <38018017+JoshuaVulcan@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:16:00 -0800 Subject: [PATCH] chore: add canonical async _delete and 204 handling in _call - async _delete(path, params=None, base_url=None) delegates to _call - _call treats 204 No Content as success and returns True (no JSON parse) - Optional base_url in _call for versioned endpoints (e.g. v2 event types) - Unifies six independent PR implementations (PRs 28,30,32,34,36,41) Co-authored-by: Cursor --- erclient/client.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/erclient/client.py b/erclient/client.py index 02bbbc0..06de6e3 100644 --- a/erclient/client.py +++ b/erclient/client.py @@ -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: @@ -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, @@ -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)