Initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class BaseError(BaseModel):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
|
||||
class BaseIdentifiedError(BaseError):
|
||||
identifier: str = Field(..., description="Unique identifier which this error references to")
|
||||
|
||||
|
||||
class NotFoundError(BaseIdentifiedError):
|
||||
"""The entity does not exist"""
|
||||
pass
|
||||
|
||||
|
||||
class AlreadyExistsError(BaseIdentifiedError):
|
||||
"""An entity being created already exists"""
|
||||
pass
|
||||
|
||||
|
||||
class ModifiedCountException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, identifier: any, message: str = 'Data not update', **data: Any):
|
||||
super().__init__()
|
||||
if identifier:
|
||||
self.message = f'data with id {identifier} not update'
|
||||
else:
|
||||
self.message = message
|
||||
|
||||
|
||||
class ValidationException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, message: str = 'validation exception', **data: Any):
|
||||
super().__init__()
|
||||
self.message = f'{message} with {data}' if data else message
|
||||
|
||||
|
||||
class RecordNotFoundException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, identifier: any = None, message: str = 'record not found', **data: Any):
|
||||
super().__init__()
|
||||
if identifier:
|
||||
self.message = f'data with id {identifier} not found'
|
||||
else:
|
||||
self.message = message
|
||||
|
||||
|
||||
class SoftDeletedException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, identifier: any, message: str = 'Data not soft deleted', **data: Any):
|
||||
super().__init__()
|
||||
if identifier:
|
||||
self.message = f'data with id {identifier} not soft deleted'
|
||||
else:
|
||||
self.message = message
|
||||
|
||||
|
||||
class NotFoundException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, identifier: any, message: str = 'Data not found', **data: Any):
|
||||
super().__init__()
|
||||
if identifier:
|
||||
self.message = f'data with id {identifier} not found'
|
||||
else:
|
||||
self.message = message
|
||||
|
||||
|
||||
class BadRequestException(Exception):
|
||||
message: str = Field(..., description="Error message or description")
|
||||
|
||||
def __init__(self, message: str = 'Data bad data', **data: Any):
|
||||
super().__init__()
|
||||
self.message = message
|
||||
Reference in New Issue
Block a user