35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
|
from enum import Enum
|
||
|
|
|
||
|
|
|
||
|
|
class MessengerErrorKind(Enum):
|
||
|
|
UNKNOWN = "unknown"
|
||
|
|
TOKEN_EXPIRED = "token_expired"
|
||
|
|
WINDOW_EXPIRED = "window_expired"
|
||
|
|
USER_BLOCKED = "user_blocked"
|
||
|
|
RATE_LIMITED = "rate_limited"
|
||
|
|
PERMISSION_DENIED = "permission_denied"
|
||
|
|
INVALID_PARAMETER = "invalid_parameter"
|
||
|
|
SERVICE_ERROR = "service_error"
|
||
|
|
MESSAGE_TAG_INVALID = "message_tag_invalid"
|
||
|
|
|
||
|
|
|
||
|
|
def classify_error(error_code: int, error_subcode: int = 0) -> MessengerErrorKind:
|
||
|
|
if error_code == 190:
|
||
|
|
return MessengerErrorKind.TOKEN_EXPIRED
|
||
|
|
if error_code == 10:
|
||
|
|
if error_subcode in (2018028, 2018108):
|
||
|
|
return MessengerErrorKind.WINDOW_EXPIRED
|
||
|
|
if error_subcode == 2018065:
|
||
|
|
return MessengerErrorKind.MESSAGE_TAG_INVALID
|
||
|
|
if error_code == 551 and error_subcode == 1545041:
|
||
|
|
return MessengerErrorKind.USER_BLOCKED
|
||
|
|
if error_code in (4, 613, 368):
|
||
|
|
return MessengerErrorKind.RATE_LIMITED
|
||
|
|
if error_code == 200:
|
||
|
|
return MessengerErrorKind.PERMISSION_DENIED
|
||
|
|
if error_code == 100:
|
||
|
|
return MessengerErrorKind.INVALID_PARAMETER
|
||
|
|
if error_code in (1, 2):
|
||
|
|
return MessengerErrorKind.SERVICE_ERROR
|
||
|
|
return MessengerErrorKind.UNKNOWN
|