From f79a6a52a889a76b274e2c923ed5dd157d7c3682 Mon Sep 17 00:00:00 2001 From: InjiChoi Date: Sat, 19 Mar 2022 15:18:04 +0900 Subject: [PATCH] feat: separate purchase exception file; #152 --- orders/exceptions.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 orders/exceptions.py diff --git a/orders/exceptions.py b/orders/exceptions.py new file mode 100644 index 00000000..edb7deee --- /dev/null +++ b/orders/exceptions.py @@ -0,0 +1,41 @@ +class AbstractPurchaseException(Exception): + def __init__(self, msg, type): + self.msg = msg + self.type = type + + self.log() + super().__init__(msg) + + def __str__(self): + return self.msg + + def log(self): + print(f"[EXCEPTION] {self.msg}") + + +class StockLackException(AbstractPurchaseException): + """결제오류(재고부족)""" + + def __init__(self, product): + super().__init__(f"{product.title}의 재고가 부족합니다", "error_stock") + + +class PriceMatchException(AbstractPurchaseException): + """결제오류(총가격 불일치)""" + + def __init__(self): + super().__init__("클라이언트 요청 금액과 DB에 저장된 금액이 일치하지 않습니다.", "error_price_match") + + +class ServerErrorException(AbstractPurchaseException): + """결제오류(서버)""" + + def __init__(self): + super().__init__("서버에 오류가 있었습니다. 다시 시도해주세요", "error_server") + + +class ValidErrorException(AbstractPurchaseException): + """결제오류(검증)""" + + def __init__(self): + super().__init__("결제 검증에 오류가 있습니다. 다시 시도해주세요", "error_valid")