Skip to content

Commit 68c450d

Browse files
Add exception to handle unauthorized connection to client
1 parent ec8d225 commit 68c450d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/Generated/ChromaApiClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function reset(): bool
318318

319319
private function handleChromaApiException(\Exception|ClientExceptionInterface $e): void
320320
{
321-
if ($e instanceof ServerException) {
321+
if ($e instanceof ClientExceptionInterface) {
322322
$errorString = $e->getResponse()->getBody()->getContents();
323323

324324
if (preg_match('/(?<={"\"error\"\:\")([^"]*)/', $errorString, $matches)) {
@@ -359,7 +359,7 @@ private function handleChromaApiException(\Exception|ClientExceptionInterface $e
359359

360360
// If the structure is 'error' => 'Collection not found'
361361
if (isset($error['error'])) {
362-
$message = $error['error'];
362+
$message = $error['message'] ?? $error['error'];
363363
$error_type = ChromaException::inferTypeFromMessage($message);
364364

365365
ChromaException::throwSpecific($message, $error_type, $e->getCode());
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
namespace Codewithkyrian\ChromaDB\Generated\Exceptions;
7+
8+
class ChromaAuthorizationException extends ChromaException
9+
{
10+
11+
}

src/Generated/Exceptions/ChromaException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static function throwSpecific(string $message, string $type, int $code)
1212
{
1313
throw match ($type) {
1414
'NotFoundError' => new ChromaNotFoundException($message, $code),
15+
'AuthorizationError' => new ChromaAuthorizationException($message, $code),
1516
'ValueError' => new ChromaValueException($message, $code),
1617
'UniqueConstraintError' => new ChromaUniqueConstraintException($message, $code),
1718
'DimensionalityError' => new ChromaDimensionalityException($message, $code),

0 commit comments

Comments
 (0)