150 lines
5.7 KiB
Python
150 lines
5.7 KiB
Python
class EveAIException(Exception):
|
|
"""Base exception class for EveAI API"""
|
|
|
|
def __init__(self, message, status_code=400, payload=None):
|
|
super().__init__()
|
|
self.message = message
|
|
self.status_code = status_code
|
|
self.payload = payload
|
|
|
|
def to_dict(self):
|
|
rv = dict(self.payload or ())
|
|
rv['message'] = self.message
|
|
rv['error'] = self.__class__.__name__
|
|
return rv
|
|
|
|
def __str__(self):
|
|
return self.message # Return the message when the exception is converted to a string
|
|
|
|
|
|
class EveAIInvalidLanguageException(EveAIException):
|
|
"""Raised when an invalid language is provided"""
|
|
|
|
def __init__(self, message="Langage is required", status_code=400, payload=None):
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIDoubleURLException(EveAIException):
|
|
"""Raised when an existing url is provided"""
|
|
|
|
def __init__(self, message="URL already exists", status_code=400, payload=None):
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIUnsupportedFileType(EveAIException):
|
|
"""Raised when an invalid file type is provided"""
|
|
|
|
def __init__(self, message="Filetype is not supported", status_code=400, payload=None):
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAINoLicenseForTenant(EveAIException):
|
|
"""Raised when no active license for a tenant is provided"""
|
|
|
|
def __init__(self, message="No license for tenant found", status_code=400, payload=None):
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAITenantNotFound(EveAIException):
|
|
"""Raised when a tenant is not found"""
|
|
|
|
def __init__(self, tenant_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
message = f"Tenant {tenant_id} not found"
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAITenantInvalid(EveAIException):
|
|
"""Raised when a tenant is invalid"""
|
|
|
|
def __init__(self, tenant_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' is not valid. Please contact the System Administrator."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAINoActiveLicense(EveAIException):
|
|
"""Raised when a tenant has no active licenses"""
|
|
|
|
def __init__(self, tenant_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' has no active licenses. Please contact the System Administrator."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIInvalidCatalog(EveAIException):
|
|
"""Raised when a catalog cannot be found"""
|
|
|
|
def __init__(self, tenant_id, catalog_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
self.catalog_id = catalog_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' has no valid catalog with ID {catalog_id}. Please contact the System Administrator."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIInvalidProcessor(EveAIException):
|
|
"""Raised when no valid processor can be found for a given Catalog ID"""
|
|
|
|
def __init__(self, tenant_id, catalog_id, file_type, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
self.catalog_id = catalog_id
|
|
self.file_type = file_type
|
|
# Construct the message dynamically
|
|
message = (f"Tenant with ID '{tenant_id}' has no valid {file_type} processor for catalog with ID {catalog_id}. "
|
|
f"Please contact the System Administrator.")
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIInvalidDocument(EveAIException):
|
|
"""Raised when a tenant has no document with given ID"""
|
|
|
|
def __init__(self, tenant_id, document_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
self.document_id = document_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' has no document with ID {document_id}."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIInvalidDocumentVersion(EveAIException):
|
|
"""Raised when a tenant has no document version with given ID"""
|
|
|
|
def __init__(self, tenant_id, document_version_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
self.document_version_id = document_version_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' has no document version with ID {document_version_id}."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAISocketInputException(EveAIException):
|
|
"""Raised when a socket call receives an invalid payload"""
|
|
|
|
def __init__(self, message, status_code=400, payload=None):
|
|
super.__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIInvalidEmbeddingModel(EveAIException):
|
|
"""Raised when no or an invalid embedding model is provided in the catalog"""
|
|
|
|
def __init__(self, tenant_id, catalog_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
self.catalog_id = catalog_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' has no or an invalid embedding model in Catalog {catalog_id}."
|
|
super().__init__(message, status_code, payload)
|
|
|
|
|
|
class EveAIDoublePartner(EveAIException):
|
|
"""Raised when there is already a partner defined for a given tenant (while registering a partner)"""
|
|
|
|
def __init__(self, tenant_id, status_code=400, payload=None):
|
|
self.tenant_id = tenant_id
|
|
# Construct the message dynamically
|
|
message = f"Tenant with ID '{tenant_id}' is already defined as a Partner."
|
|
super().__init__(message, status_code, payload)
|
|
|