move app to gatehouse-app
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Exceptions package."""
|
||||
from gatehouse_app.exceptions.base import BaseAPIException
|
||||
from gatehouse_app.exceptions.auth_exceptions import (
|
||||
UnauthorizedError,
|
||||
ForbiddenError,
|
||||
InvalidCredentialsError,
|
||||
AccountSuspendedError,
|
||||
AccountInactiveError,
|
||||
SessionExpiredError,
|
||||
InvalidTokenError,
|
||||
)
|
||||
from gatehouse_app.exceptions.validation_exceptions import (
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
BadRequestError,
|
||||
RateLimitExceededError,
|
||||
EmailAlreadyExistsError,
|
||||
OrganizationNotFoundError,
|
||||
UserNotFoundError,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"BaseAPIException",
|
||||
"UnauthorizedError",
|
||||
"ForbiddenError",
|
||||
"InvalidCredentialsError",
|
||||
"AccountSuspendedError",
|
||||
"AccountInactiveError",
|
||||
"SessionExpiredError",
|
||||
"InvalidTokenError",
|
||||
"ValidationError",
|
||||
"NotFoundError",
|
||||
"ConflictError",
|
||||
"BadRequestError",
|
||||
"RateLimitExceededError",
|
||||
"EmailAlreadyExistsError",
|
||||
"OrganizationNotFoundError",
|
||||
"UserNotFoundError",
|
||||
]
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Authentication and authorization exceptions."""
|
||||
from gatehouse_app.exceptions.base import BaseAPIException
|
||||
|
||||
|
||||
class UnauthorizedError(BaseAPIException):
|
||||
"""Raised when authentication is required but not provided."""
|
||||
|
||||
status_code = 401
|
||||
error_type = "AUTHENTICATION_ERROR"
|
||||
message = "Authentication required"
|
||||
|
||||
|
||||
class ForbiddenError(BaseAPIException):
|
||||
"""Raised when user lacks permissions for the requested action."""
|
||||
|
||||
status_code = 403
|
||||
error_type = "AUTHORIZATION_ERROR"
|
||||
message = "You don't have permission to perform this action"
|
||||
|
||||
|
||||
class InvalidCredentialsError(BaseAPIException):
|
||||
"""Raised when login credentials are invalid."""
|
||||
|
||||
status_code = 401
|
||||
error_type = "AUTHENTICATION_ERROR"
|
||||
message = "Invalid email or password"
|
||||
|
||||
|
||||
class AccountSuspendedError(BaseAPIException):
|
||||
"""Raised when user account is suspended."""
|
||||
|
||||
status_code = 403
|
||||
error_type = "AUTHORIZATION_ERROR"
|
||||
message = "Your account has been suspended"
|
||||
|
||||
|
||||
class AccountInactiveError(BaseAPIException):
|
||||
"""Raised when user account is inactive."""
|
||||
|
||||
status_code = 403
|
||||
error_type = "AUTHORIZATION_ERROR"
|
||||
message = "Your account is inactive"
|
||||
|
||||
|
||||
class SessionExpiredError(BaseAPIException):
|
||||
"""Raised when user session has expired."""
|
||||
|
||||
status_code = 401
|
||||
error_type = "AUTHENTICATION_ERROR"
|
||||
message = "Your session has expired. Please log in again"
|
||||
|
||||
|
||||
class InvalidTokenError(BaseAPIException):
|
||||
"""Raised when authentication token is invalid."""
|
||||
|
||||
status_code = 401
|
||||
error_type = "AUTHENTICATION_ERROR"
|
||||
message = "Invalid authentication token"
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Base exception classes."""
|
||||
|
||||
|
||||
class BaseAPIException(Exception):
|
||||
"""Base exception for all API errors."""
|
||||
|
||||
status_code = 500
|
||||
error_type = "INTERNAL_ERROR"
|
||||
message = "An unexpected error occurred"
|
||||
|
||||
def __init__(self, message=None, error_details=None):
|
||||
"""
|
||||
Initialize exception.
|
||||
|
||||
Args:
|
||||
message: Custom error message
|
||||
error_details: Additional error details dictionary
|
||||
"""
|
||||
super().__init__()
|
||||
if message:
|
||||
self.message = message
|
||||
self.error_details = error_details or {}
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert exception to dictionary for API response."""
|
||||
return {
|
||||
"error_type": self.error_type,
|
||||
"message": self.message,
|
||||
"details": self.error_details,
|
||||
"status_code": self.status_code,
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Validation and resource exceptions."""
|
||||
from gatehouse_app.exceptions.base import BaseAPIException
|
||||
|
||||
|
||||
class ValidationError(BaseAPIException):
|
||||
"""Raised when request data validation fails."""
|
||||
|
||||
status_code = 400
|
||||
error_type = "VALIDATION_ERROR"
|
||||
message = "Validation failed"
|
||||
|
||||
|
||||
class NotFoundError(BaseAPIException):
|
||||
"""Raised when a requested resource is not found."""
|
||||
|
||||
status_code = 404
|
||||
error_type = "NOT_FOUND"
|
||||
message = "Resource not found"
|
||||
|
||||
|
||||
class ConflictError(BaseAPIException):
|
||||
"""Raised when a resource conflict occurs."""
|
||||
|
||||
status_code = 409
|
||||
error_type = "CONFLICT"
|
||||
message = "Resource conflict"
|
||||
|
||||
|
||||
class BadRequestError(BaseAPIException):
|
||||
"""Raised when the request is malformed or invalid."""
|
||||
|
||||
status_code = 400
|
||||
error_type = "BAD_REQUEST"
|
||||
message = "Bad request"
|
||||
|
||||
|
||||
class RateLimitExceededError(BaseAPIException):
|
||||
"""Raised when rate limit is exceeded."""
|
||||
|
||||
status_code = 429
|
||||
error_type = "RATE_LIMIT_EXCEEDED"
|
||||
message = "Too many requests. Please try again later"
|
||||
|
||||
|
||||
class EmailAlreadyExistsError(ConflictError):
|
||||
"""Raised when attempting to register with an existing email."""
|
||||
|
||||
message = "Email address already registered"
|
||||
|
||||
|
||||
class OrganizationNotFoundError(NotFoundError):
|
||||
"""Raised when organization is not found."""
|
||||
|
||||
message = "Organization not found"
|
||||
|
||||
|
||||
class UserNotFoundError(NotFoundError):
|
||||
"""Raised when user is not found."""
|
||||
|
||||
message = "User not found"
|
||||
Reference in New Issue
Block a user