diff --git a/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php b/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php new file mode 100644 index 000000000..852c20f97 --- /dev/null +++ b/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\AI\Platform\Tests\Bridge\Gemini\Gemini; + +use PHPUnit\Framework\TestCase; +use Symfony\AI\Platform\Bridge\Gemini\Gemini\ResultConverter; +use Symfony\AI\Platform\Exception\RuntimeException; +use Symfony\AI\Platform\Result\RawHttpResult; +use Symfony\Contracts\HttpClient\ResponseInterface; + +/** + * @author Oskar Stark + */ +final class ResultConverterTest extends TestCase +{ + public function testConvertThrowsExceptionWithDetailedErrorInformation() + { + $converter = new ResultConverter(); + $httpResponse = self::createMock(ResponseInterface::class); + $httpResponse->method('getStatusCode')->willReturn(400); + $httpResponse->method('toArray')->willReturn([ + 'error' => [ + 'code' => 400, + 'status' => 'INVALID_ARGUMENT', + 'message' => 'Invalid request: The model does not support this feature.', + ], + ]); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Error "400" - "INVALID_ARGUMENT": "Invalid request: The model does not support this feature.".'); + + $converter->convert(new RawHttpResult($httpResponse)); + } +} diff --git a/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php b/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php index 185c47e1e..f1a90f2b9 100644 --- a/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php +++ b/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php @@ -226,4 +226,23 @@ public function testThrowsBadRequestExceptionOnBadRequestResponseWithNoResponseB $converter->convert(new RawHttpResult($httpResponse)); } + + public function testThrowsDetailedErrorException() + { + $converter = new ResultConverter(); + $httpResponse = self::createMock(ResponseInterface::class); + $httpResponse->method('toArray')->willReturn([ + 'error' => [ + 'code' => 'invalid_request_error', + 'type' => 'invalid_request', + 'param' => 'model', + 'message' => 'The model `gpt-5` does not exist', + ], + ]); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Error "invalid_request_error"-invalid_request (model): "The model `gpt-5` does not exist".'); + + $converter->convert(new RawHttpResult($httpResponse)); + } }