Skip to content

Commit 0a6849c

Browse files
volodstaimiclaude
andcommitted
Return an empty result for 204 No Content (0.1.1)
DELETE /v1/webhook-endpoints/{id} answers 204 with no body. The client reported that success as INVALID_RESPONSE. A 204 now returns an empty result; a 200 with an empty body is still rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6ae5362 commit 0a6849c

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ signatures in your receiver according to the API documentation.
8383
later. It rejects absolute URLs, traversal paths and redirects. Custom API
8484
origins must use HTTPS, except loopback HTTP for local development. The default
8585
origin is `https://www.transcriptdock.com`; the apex domain redirects.
86+
A success with no body (204 No Content, such as deleting a webhook endpoint)
87+
returns an empty dictionary, or an empty string with `text=True`.
8688

8789
## Errors
8890

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "transcriptdock"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "Python client for the Transcript Dock video transcription API"
99
readme = "README.md"
1010
requires-python = ">=3.10"

‎src/transcriptdock/__init__.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from urllib.parse import quote, unquote, urlencode, urlsplit
1010
from urllib.request import HTTPRedirectHandler, Request, build_opener
1111

12-
__version__ = "0.1.0"
12+
__version__ = "0.1.1"
1313

1414

1515
class ApiError(Exception):
@@ -107,6 +107,7 @@ def request(self, method, path, *, body=None, query=None, idempotency_key=None,
107107
request = Request(url, data=data, headers=headers, method=method)
108108
try:
109109
with self._opener.open(request, timeout=self.timeout if timeout is None else _positive(timeout, "timeout")) as response:
110+
status = response.status
110111
raw = response.read().decode("utf-8")
111112
except HTTPError as exc:
112113
try:
@@ -126,6 +127,9 @@ def request(self, method, path, *, body=None, query=None, idempotency_key=None,
126127
raise ApiError("NETWORK_ERROR", "Could not reach the API. Check the job before retrying a submission.", retryable=True) from None
127128
except UnicodeError:
128129
raise ApiError("INVALID_RESPONSE", "The API response is not UTF-8 text.") from None
130+
if status == 204:
131+
# No Content: a success without a body, for example deleting a webhook endpoint.
132+
return "" if text else {}
129133
if text:
130134
return raw
131135
try:

‎tests/test_client.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ def do_GET(self):
2222
def do_POST(self):
2323
self.respond()
2424

25+
def do_DELETE(self):
26+
self.respond()
27+
2528
def respond(self):
2629
body = self.rfile.read(int(self.headers.get("Content-Length", "0")))
2730
self.calls.append((self.command, self.path, dict(self.headers), body))
2831
code, headers = 200, {}
2932
payload = {"id": "fixture-job", "status": "succeeded", "future_field": 42}
33+
if self.path == "/v1/no-content":
34+
self.send_response(204)
35+
self.end_headers()
36+
return
3037
if self.path == "/v1/redirect":
3138
code, headers, payload = 302, {"Location": "/v1/leak"}, {}
3239
elif self.path == "/v1/rate-limit":
@@ -38,6 +45,8 @@ def respond(self):
3845
payload = {"error": {"code": label, "message": "Fixture rejection", "retryable": False}}
3946
elif self.path == "/v1/gateway":
4047
code, payload = 502, b"<html>upstream failed</html>"
48+
elif self.path == "/v1/empty-ok":
49+
payload = b""
4150
elif self.path == "/v1/malformed":
4251
payload = b"not json"
4352
elif self.path.endswith("/export?format=srt"):
@@ -113,6 +122,13 @@ def test_redirect_never_followed(self):
113122
self.assertEqual(ctx.exception.status, 302)
114123
self.assertEqual([x[1] for x in Handler.calls], ["/v1/redirect"])
115124

125+
def test_no_content_success_returns_empty_result(self):
126+
self.assertEqual(self.client.request("DELETE", "/v1/no-content"), {})
127+
self.assertEqual(self.client.request("DELETE", "/v1/no-content", text=True), "")
128+
with self.assertRaises(ApiError) as ctx:
129+
self.client.request("GET", "/v1/empty-ok")
130+
self.assertEqual(ctx.exception.code, "INVALID_RESPONSE")
131+
116132
def test_query_and_id_encoding_and_raw_export(self):
117133
self.client.list_jobs(cursor="a/b?c&d", limit=7)
118134
self.assertIn("cursor=a%2Fb%3Fc%26d", Handler.calls[-1][1])

0 commit comments

Comments
 (0)