113 lines
3.9 KiB
Python
113 lines
3.9 KiB
Python
from fastapi import HTTPException
|
|
|
|
class BaseCustomException(HTTPException):
|
|
"""커스텀 예외의 기본 클래스"""
|
|
|
|
def __init__(self, error_code: str, error_message: str, http_status_code: int = 400):
|
|
super().__init__(status_code=http_status_code, detail=error_message)
|
|
self.error_code = error_code
|
|
self.error_message = error_message
|
|
self.http_status_code = http_status_code
|
|
|
|
# ===========================================
|
|
# 비즈니스 로직 관련 예외들
|
|
# ===========================================
|
|
|
|
class UserIdAlreadyExistsError(BaseCustomException):
|
|
"""사용자 ID 중복 예외"""
|
|
|
|
def __init__(self, message: str = "이미 존재하는 유저 아이디입니다."):
|
|
super().__init__(
|
|
error_code="USER_ID_ALREADY_EXISTS",
|
|
error_message=message,
|
|
http_status_code=409
|
|
)
|
|
|
|
class UserNotFoundError(BaseCustomException):
|
|
"""사용자 찾을 수 없음 예외"""
|
|
|
|
def __init__(self, message: str = "사용자를 찾을 수 없습니다."):
|
|
super().__init__(
|
|
error_code="USER_NOT_FOUND",
|
|
error_message=message,
|
|
http_status_code=404
|
|
)
|
|
|
|
class PasswordIncorrectError(BaseCustomException):
|
|
"""비밀번호 올바르지 않음 예외"""
|
|
|
|
def __init__(self, message: str = "비밀번호가 올바르지 않습니다."):
|
|
super().__init__(
|
|
error_code="PASSWORD_INCORRECT",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
|
|
# ===========================================
|
|
# 소셜 로그인 관련 예외들
|
|
# ===========================================
|
|
|
|
class OAuthConfigurationError(BaseCustomException):
|
|
"""OAuth 설정 오류"""
|
|
def __init__(self, message: str = "OAuth 설정에 오류가 있습니다."):
|
|
super().__init__(
|
|
error_code="OAUTH_CONFIGURATION_ERROR",
|
|
error_message=message,
|
|
http_status_code=500
|
|
)
|
|
|
|
class OAuthStateInvalidError(BaseCustomException):
|
|
"""OAuth State 검증 실패"""
|
|
def __init__(self, message: str = "OAuth state가 유효하지 않습니다."):
|
|
super().__init__(
|
|
error_code="OAUTH_STATE_INVALID",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
class OAuthTokenExchangeError(BaseCustomException):
|
|
"""OAuth 토큰 교환 실패"""
|
|
def __init__(self, message: str = "OAuth 토큰 교환에 실패했습니다."):
|
|
super().__init__(
|
|
error_code="OAUTH_TOKEN_EXCHANGE_ERROR",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
class OAuthUserInfoError(BaseCustomException):
|
|
"""OAuth 사용자 정보 추출 실패"""
|
|
def __init__(self, message: str = "사용자 정보를 가져올 수 없습니다."):
|
|
super().__init__(
|
|
error_code="OAUTH_USER_INFO_ERROR",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
class OAuthTempTokenError(BaseCustomException):
|
|
"""임시 토큰 관련 오류"""
|
|
def __init__(self, message: str = "임시 토큰이 유효하지 않거나 만료되었습니다."):
|
|
super().__init__(
|
|
error_code="OAUTH_TEMP_TOKEN_ERROR",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
class ItemNotFoundError(BaseCustomException):
|
|
def __init__(self, message: str = "업체를 찾을 수 없습니다."):
|
|
super().__init__(
|
|
error_code="item_not_found",
|
|
error_message=message,
|
|
http_status_code=400
|
|
)
|
|
|
|
class OrderNotFoundError(Exception):
|
|
def __init__(self, message: str = "해당 주문을 찾을 수 없습니다."):
|
|
self.message = message
|
|
super().__init__(self.message)
|
|
|
|
|
|
class VideoNotFoundError(Exception):
|
|
def __init__(self, message: str = "해당 주문에 대한 영상을 찾을 수 없습니다."):
|
|
self.message = message
|
|
super().__init__(self.message) |