|
215 | 215 | });
|
216 | 216 | });
|
217 | 217 |
|
| 218 | +test('error message may be empty', function () { |
| 219 | + $payload = Payload::create('completions', ['model' => 'gpt-4']); |
| 220 | + |
| 221 | + $response = new Response(404, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([ |
| 222 | + 'error' => [ |
| 223 | + 'message' => '', |
| 224 | + 'type' => 'invalid_request_error', |
| 225 | + 'param' => null, |
| 226 | + 'code' => 'invalid_api_key', |
| 227 | + ], |
| 228 | + ])); |
| 229 | + |
| 230 | + $this->client |
| 231 | + ->shouldReceive('sendRequest') |
| 232 | + ->once() |
| 233 | + ->andReturn($response); |
| 234 | + |
| 235 | + expect(fn () => $this->http->requestObject($payload)) |
| 236 | + ->toThrow(function (ErrorException $e) { |
| 237 | + expect($e->getMessage())->toBe('invalid_api_key') |
| 238 | + ->and($e->getErrorMessage())->toBe('invalid_api_key') |
| 239 | + ->and($e->getErrorCode())->toBe('invalid_api_key') |
| 240 | + ->and($e->getErrorType())->toBe('invalid_request_error'); |
| 241 | + }); |
| 242 | +}); |
| 243 | + |
| 244 | +test('error message and code may be empty', function () { |
| 245 | + $payload = Payload::create('completions', ['model' => 'gpt-4']); |
| 246 | + |
| 247 | + $response = new Response(404, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([ |
| 248 | + 'error' => [ |
| 249 | + 'message' => '', |
| 250 | + 'type' => 'invalid_request_error', |
| 251 | + 'param' => null, |
| 252 | + 'code' => null, |
| 253 | + ], |
| 254 | + ])); |
| 255 | + |
| 256 | + $this->client |
| 257 | + ->shouldReceive('sendRequest') |
| 258 | + ->once() |
| 259 | + ->andReturn($response); |
| 260 | + |
| 261 | + expect(fn () => $this->http->requestObject($payload)) |
| 262 | + ->toThrow(function (ErrorException $e) { |
| 263 | + expect($e->getMessage())->toBe('Unknown error') |
| 264 | + ->and($e->getErrorMessage())->toBe('Unknown error') |
| 265 | + ->and($e->getErrorCode())->toBeNull() |
| 266 | + ->and($e->getErrorType())->toBe('invalid_request_error'); |
| 267 | + }); |
| 268 | +}); |
| 269 | + |
218 | 270 | test('request object client errors', function () {
|
219 | 271 | $payload = Payload::list('models');
|
220 | 272 |
|
|
0 commit comments