m-gm/framework/response_code.py

46 lines
1.3 KiB
Python
Raw Normal View History

2025-03-19 18:02:29 +08:00
from enum import unique
from enum import Enum
class MinCustomException(Exception):
def __init__(self, error):
self.error = error
super().__init__(self.error)
@unique
class RequestMethods(Enum):
GET = 1
POST = 2
PUT = 3
DELETE = 4
@unique
class ResponseCode(Enum):
def __init__(self, code: int, message: str) -> None:
self.code: int = code
self.message: str = message
# Main
RESPONSE_100_CONTINUE = 100, "Continue"
RESPONSE_200_SUCCESS = 200, "Success"
RESPONSE_201_DEBUG = 201, "Debug"
RESPONSE_502_BAD_GATEWAY = 502, "BadGateway"
RESPONSE_500_SERVER_ERROR = 500, "ServerError"
RESPONSE_405_METHODS_NOT_ALLOW = 405, "METHODS NOT ALLOW"
RESPONSE_501_NOT_IMPLEMENTED_EXCEPTION = 501.1, "NOT IMPLEMENTED" # 数据库语句异常
RESPONSE_501_NOT_IMPLEMENTED_NULL = 501.2, "NOT IMPLEMENTED" # 数据库语句异常
RESPONSE_400_BAD_REQUESTS_JSON = 400.1, "JsonDecodeError"
RESPONSE_401_Unauthorized = 401, "Unauthorized"
RESPONSE_401_TOKEN_INVALID = 401.1, "TokenInvalid"
RESPONSE_401_TOKEN_EXPIRE = 401.2, "TokenExpire"
# Request Params Warning
RESPONSE_PARAMS_IS_NULL = 10400, "未获取所有参数"
RESPONSE_PARAMS_IS_VALID = 10401, "请求参数错误"
def return_tuple(self) -> tuple:
return self.code, self.message