Spaces:
Runtime error
Runtime error
File size: 1,293 Bytes
4a51346 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from abc import abstractmethod
from typing import Dict, Type
from overrides import overrides, EnforceOverrides
class ChromaError(Exception, EnforceOverrides):
def code(self) -> int:
"""Return an appropriate HTTP response code for this error"""
return 400 # Bad Request
def message(self) -> str:
return ", ".join(self.args)
@classmethod
@abstractmethod
def name(self) -> str:
"""Return the error name"""
pass
class InvalidDimensionException(ChromaError):
@classmethod
@overrides
def name(cls) -> str:
return "InvalidDimension"
class IDAlreadyExistsError(ChromaError):
@overrides
def code(self) -> int:
return 409 # Conflict
@classmethod
@overrides
def name(cls) -> str:
return "IDAlreadyExists"
class DuplicateIDError(ChromaError):
@classmethod
@overrides
def name(cls) -> str:
return "DuplicateID"
class InvalidUUIDError(ChromaError):
@classmethod
@overrides
def name(cls) -> str:
return "InvalidUUID"
error_types: Dict[str, Type[ChromaError]] = {
"InvalidDimension": InvalidDimensionException,
"IDAlreadyExists": IDAlreadyExistsError,
"DuplicateID": DuplicateIDError,
"InvalidUUID": InvalidUUIDError,
}
|