Skip to content

Commit 8fb30ba

Browse files
committed
minor #702 [Platform] Add error handling tests (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Platform] Add error handling tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | Follows #608 | License | MIT Commits ------- cac9a7e [Platform] Add error handling tests
2 parents 5434201 + cac9a7e commit 8fb30ba

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Platform\Tests\Bridge\Gemini\Gemini;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\AI\Platform\Bridge\Gemini\Gemini\ResultConverter;
16+
use Symfony\AI\Platform\Exception\RuntimeException;
17+
use Symfony\AI\Platform\Result\RawHttpResult;
18+
use Symfony\Contracts\HttpClient\ResponseInterface;
19+
20+
/**
21+
* @author Oskar Stark <[email protected]>
22+
*/
23+
final class ResultConverterTest extends TestCase
24+
{
25+
public function testConvertThrowsExceptionWithDetailedErrorInformation()
26+
{
27+
$converter = new ResultConverter();
28+
$httpResponse = self::createMock(ResponseInterface::class);
29+
$httpResponse->method('getStatusCode')->willReturn(400);
30+
$httpResponse->method('toArray')->willReturn([
31+
'error' => [
32+
'code' => 400,
33+
'status' => 'INVALID_ARGUMENT',
34+
'message' => 'Invalid request: The model does not support this feature.',
35+
],
36+
]);
37+
38+
$this->expectException(RuntimeException::class);
39+
$this->expectExceptionMessage('Error "400" - "INVALID_ARGUMENT": "Invalid request: The model does not support this feature.".');
40+
41+
$converter->convert(new RawHttpResult($httpResponse));
42+
}
43+
}

src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,23 @@ public function testThrowsBadRequestExceptionOnBadRequestResponseWithNoResponseB
226226

227227
$converter->convert(new RawHttpResult($httpResponse));
228228
}
229+
230+
public function testThrowsDetailedErrorException()
231+
{
232+
$converter = new ResultConverter();
233+
$httpResponse = self::createMock(ResponseInterface::class);
234+
$httpResponse->method('toArray')->willReturn([
235+
'error' => [
236+
'code' => 'invalid_request_error',
237+
'type' => 'invalid_request',
238+
'param' => 'model',
239+
'message' => 'The model `gpt-5` does not exist',
240+
],
241+
]);
242+
243+
$this->expectException(RuntimeException::class);
244+
$this->expectExceptionMessage('Error "invalid_request_error"-invalid_request (model): "The model `gpt-5` does not exist".');
245+
246+
$converter->convert(new RawHttpResult($httpResponse));
247+
}
229248
}

0 commit comments

Comments
 (0)