forked from CodeWithKyrian/chromadb-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChromaException.php
More file actions
38 lines (32 loc) · 1.58 KB
/
ChromaException.php
File metadata and controls
38 lines (32 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Codewithkyrian\ChromaDB\Generated\Exceptions;
class ChromaException extends \Exception
{
public static function throwSpecific(string $message, string $type, int $code)
{
throw match ($type) {
'NotFoundError' => new ChromaNotFoundException($message, $code),
'AuthorizationError' => new ChromaAuthorizationException($message, $code),
'ValueError' => new ChromaValueException($message, $code),
'UniqueConstraintError' => new ChromaUniqueConstraintException($message, $code),
'DimensionalityError' => new ChromaDimensionalityException($message, $code),
'InvalidCollection' => new ChromaInvalidCollectionException($message, $code),
'TypeError' => new ChromaTypeException($message, $code),
'InvalidArgumentError' => new ChromaInvalidArgumentException($message, $code),
default => new self($message, $code),
};
}
public static function inferTypeFromMessage(string $message): string
{
return match (true) {
str_contains($message, 'NotFoundError') => 'NotFoundError',
str_contains($message, 'AuthorizationError') => 'AuthorizationError',
str_contains($message, 'Forbidden') => 'AuthorizationError',
str_contains($message, 'UniqueConstraintError') => 'UniqueConstraintError',
str_contains($message, 'ValueError') => 'ValueError',
str_contains($message, 'dimensionality') => 'DimensionalityError',
default => 'UnknownError',
};
}
}