Skip to content

Commit 273cc37

Browse files
committed
Fix #692 [Bug]: Passing invalid parameters to gemini throws Undefined array key "choices" /www/htdocs/vendor/openai-php/client/src/Responses/Chat/CreateResponse.php 54
Change-Id: Ibbf64cc554ef68844fd8338583f3fc8ec5fde413
1 parent d95eda4 commit 273cc37

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Transporters/HttpTransporter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ private function throwIfJsonError(ResponseInterface $response, string|ResponseIn
172172
}
173173

174174
try {
175-
/** @var array{error?: string|array{message: string|array<int, string>, type: string, code: string}} $data */
175+
/** @var (array{error?: string|array{message: string|array<int, string>, type: string, code: string}})|(array{0?: array{error?: string|array{message: string|array<int, string>, code: string}}}) $data */
176176
$data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
177177

178178
if (isset($data['error'])) {
179179
throw new ErrorException($data['error'], $response);
180+
} elseif (isset($data[0]['error'])) {
181+
throw new ErrorException($data[0]['error'], $response);
180182
}
181183
} catch (JsonException $jsonException) {
182184
throw new UnserializableResponse($jsonException, $response);

0 commit comments

Comments
 (0)