Skip to content

Commit 04b9bc8

Browse files
volodstaimiclaude
andcommitted
Return an empty array 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 ab92898 commit 04b9bc8

4 files changed

Lines changed: 14 additions & 1 deletion

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
@@ -39,6 +39,8 @@ Core methods: `capabilities`, `createJob`, `getJob`, `getTranscript`,
3939
`request($method, $path, $body, $query, $idempotencyKey)` for the complete public
4040
API, including batches, discovery, upload slots, usage and webhook endpoints.
4141
Bodies use the [API contract's exact fields](https://www.transcriptdock.com/docs/openapi.yaml).
42+
A success with no body (204 No Content, such as deleting a webhook endpoint)
43+
returns an empty array, or an empty string in text mode.
4244

4345
Responses are associative arrays preserving all API fields and timing units.
4446
Exports are raw JSON, TXT, SRT or VTT strings. Inspect status before using a

‎src/Client.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function request(string $method, string $path, ?array $body = null, array
4141
}
4242
$seconds = $timeout ?? $this->timeout;
4343
self::positive($seconds);
44-
$headers = ['Authorization: Bearer ' . $this->apiKey, 'Accept: application/json', 'User-Agent: transcriptdock-php/0.1.0'];
44+
$headers = ['Authorization: Bearer ' . $this->apiKey, 'Accept: application/json', 'User-Agent: transcriptdock-php/0.1.1'];
4545
if ($idempotencyKey !== null) $headers[] = 'Idempotency-Key: ' . $idempotencyKey;
4646
$url = $this->baseUrl . $path;
4747
$query = array_filter($query, fn($v) => $v !== null);
@@ -69,6 +69,8 @@ public function request(string $method, string $path, ?array $body = null, array
6969
is_string($envelope['request_id'] ?? null) ? $this->redact($envelope['request_id']) : null,
7070
is_int($error['retry_after_seconds'] ?? null) ? $error['retry_after_seconds'] : null);
7171
}
72+
// No Content: a success without a body, for example deleting a webhook endpoint.
73+
if ($status === 204) return $text ? '' : [];
7274
if ($text) return $raw;
7375
try {
7476
$decoded = json_decode($raw, false, 512, JSON_THROW_ON_ERROR);

‎tests/client_check.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function raises(string $type, callable $f): Throwable {
3737
check($client->request('POST', $path, ['fixture' => true], idempotencyKey: 'fixture-generic-01')['request']['method'] === 'POST', 'generic submission failed');
3838
}
3939
check($client->request('DELETE', '/v1/transcripts/fixture')['request']['method'] === 'DELETE', 'delete dispatch failed');
40+
check($client->request('DELETE', '/v1/no-content') === [], 'no content success not empty');
41+
check($client->request('DELETE', '/v1/no-content', text: true) === '', 'no content text not empty');
42+
check(raises(ApiError::class, fn() => $client->request('GET', '/v1/empty-ok'))->errorCode === 'INVALID_RESPONSE', 'empty 200 accepted');
4043
foreach (['http://example.com', 'https://user:pass@example.com', 'https://example.com/path', 'https://example.com?x=1'] as $url) raises(InvalidArgumentException::class, fn() => new Client('fixture-key', $url));
4144
raises(InvalidArgumentException::class, fn() => new Client("bad\nkey"));
4245
raises(InvalidArgumentException::class, fn() => $client->createJob([], "bad\nreplay"));

0 commit comments

Comments
 (0)