Skip to content

Commit 027aece

Browse files
volodstaimiclaude
andcommitted
Return an empty hash for 204 No Content
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 48dc0e3 commit 027aece

4 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎.ci/fixture.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def respond(self):
3636
'body': json.loads(raw) if raw else None,
3737
'idempotency_key': self.headers.get('Idempotency-Key'),
3838
'authorized': self.headers.get('Authorization') == 'Bearer ' + KEY}}
39+
if path == '/v1/no-content':
40+
self.send_response(204)
41+
self.end_headers()
42+
return
3943
if path == '/v1/redirect':
4044
self.send_response(302)
4145
self.send_header('Location', '/v1/credential-leak')
@@ -52,6 +56,8 @@ def respond(self):
5256
status, payload = 502, b'<html>gateway failed</html>'
5357
elif path == '/v1/error-shape':
5458
status, payload = 500, ['not an error object']
59+
elif path == '/v1/empty-ok':
60+
payload = b''
5561
elif path == '/v1/malformed':
5662
payload = b'not-json'
5763
elif path == '/v1/array':

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ and `wait_for_job` provide the core flow. All public endpoints are available
3838
through `request(method, path, body: nil, query: {}, idempotency_key: nil)`.
3939
Use the exact fields in the [API contract](https://www.transcriptdock.com/docs/openapi.yaml)
4040
for batches, discovery, usage, upload slots and webhook endpoints.
41+
A success with no body (204 No Content, such as deleting a webhook endpoint)
42+
returns an empty hash, or an empty string with `text: true`.
4143

4244
Responses are hashes retaining future fields and original timing units.
4345
Exports return the raw JSON, TXT, SRT or VTT string. Polling returns failed and

‎lib/transcriptdock.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def request(method, path, body: nil, query: {}, idempotency_key: nil, text: fals
8080
raise ApiError.new(redact(error['code'] || 'HTTP_ERROR'), redact(error['message'] || "Request failed with status #{status}."), status: status,
8181
retryable: error.fetch('retryable', status == 429 || status >= 500), request_id: envelope['request_id'] && redact(envelope['request_id']), retry_after_seconds: error['retry_after_seconds'])
8282
end
83+
# No Content: a success without a body, for example deleting a webhook endpoint.
84+
return(text ? '' : {}) if status == 204
8385
return response.body if text
8486
begin
8587
result = JSON.parse(response.body)

‎test/client_check.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def raises(type)
4040
check(client.request('POST', path, body: {fixture: true}, idempotency_key: 'fixture-generic-01')['request']['method'] == 'POST', 'generic submission failed')
4141
end
4242
check(client.request('DELETE', '/v1/transcripts/fixture')['request']['method'] == 'DELETE', 'delete dispatch failed')
43+
check(client.request('DELETE', '/v1/no-content') == {}, 'no content success not empty')
44+
check(client.request('DELETE', '/v1/no-content', text: true) == '', 'no content text not empty')
45+
check(raises(TranscriptDock::ApiError) { client.request('GET', '/v1/empty-ok') }.code == 'INVALID_RESPONSE', 'empty 200 accepted')
4346
['http://example.com', 'https://user:pass@example.com', 'https://example.com/path', 'https://example.com?x=1'].each do |url|
4447
raises(ArgumentError) { TranscriptDock::Client.new('fixture-key', base_url: url) }
4548
end

0 commit comments

Comments
 (0)