matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/kt/client/error_helper.py

126 lines
7.1 KiB
Python
Raw Normal View History

2022-02-25 02:22:50 -05:00
# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge.
# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Internal helpers for error handling."""
from __future__ import annotations
from typing import NoReturn, Type
from .errors import (
CommandException,
AuthenticationRequired,
DeviceVerificationRequired,
IncorrectPasscode,
IncorrectPassword,
InvalidAccessToken,
)
from ..types.request import RootCommandResult, KnownDataStatusCode
from ..types.api.auth_api_client import KnownAuthStatusCode
def raise_unsuccessful_response(resp: RootCommandResult) -> NoReturn:
raise _error_code_class_map.get(resp.status, CommandException)(resp)
_error_code_class_map: dict[KnownAuthStatusCode | KnownDataStatusCode | int, Type[CommandException]] = {
#KnownAuthStatusCode.INVALID_PHONE_NUMBER: "Invalid phone number",
#KnownAuthStatusCode.SUCCESS_WITH_ACCOUNT: "Success",
#KnownAuthStatusCode.SUCCESS_WITH_DEVICE_CHANGED: "Success (device changed)",
KnownAuthStatusCode.MISMATCH_PASSWORD: IncorrectPassword,
#KnownAuthStatusCode.EXCEED_LOGIN_LIMIT: "Login limit exceeded",
#KnownAuthStatusCode.MISMATCH_PHONE_NUMBER: "Phone number mismatch",
#KnownAuthStatusCode.EXCEED_PHONE_NUMBER_CHECK_LIMIT: "Phone number limit exceeded",
#KnownAuthStatusCode.NOT_EXIST_ACCOUNT: "Account does not exist",
#KnownAuthStatusCode.NEED_CHECK_PHONE_NUMBER: "Must check phone number",
#KnownAuthStatusCode.NEED_CHECK_QUIZ: "Must check quiz",
#KnownAuthStatusCode.DORMANT_ACCOUNT: "Dormant account",
#KnownAuthStatusCode.RESTRICTED_ACCOUNT: "Restricted account",
KnownAuthStatusCode.LOGIN_FAILED: IncorrectPassword,
#KnownAuthStatusCode.NOT_VERIFIED_EMAIL: "Unverified email address",
#KnownAuthStatusCode.MOBILE_UNREGISTERED: "Mobile device not registered",
#KnownAuthStatusCode.UNKNOWN_PHONE_NUMBER: "Unknown phone number",
#KnownAuthStatusCode.SUCCESS_SAME_USER: "Success (same user)",
#KnownAuthStatusCode.SUCCESS_SAME_USER_BY_MIGRATION: "Success (same user by migration)",
#KnownAuthStatusCode.TOO_MANY_REQUEST_A_DAY: "Too many requests a day",
#KnownAuthStatusCode.TOO_MANY_REQUEST_AT_A_TIME: " Too many requests at a time",
KnownAuthStatusCode.MISMATCH_PASSCODE: IncorrectPasscode,
#KnownAuthStatusCode.EXCEED_DAILY_REQUEST_LIMIT: "Daily request limit exceeded",
#KnownAuthStatusCode.EXCEED_DAILY_REQUEST_LIMIT_VOICECALL: "Daily voicecall limit exceeded",
#KnownAuthStatusCode.EXCEED_DAILY_REQUEST_LIMIT_WITHOUT_TOKEN: "Daily tokenless request limit exceeded",
KnownAuthStatusCode.DEVICE_NOT_REGISTERED: DeviceVerificationRequired,
#KnownAuthStatusCode.ANOTHER_LOGON: "Another logon detected",
#KnownAuthStatusCode.DEVICE_REGISTER_FAILED: "Device registration failed",
#KnownAuthStatusCode.INVALID_DEVICE_REGISTER: "Invalid device",
KnownAuthStatusCode.INVALID_PASSCODE: IncorrectPasscode,
#KnownAuthStatusCode.PASSCODE_REQUEST_FAILED: "Passcode request failed",
#KnownAuthStatusCode.NEED_TERMS_AGREE: "Must agree to terms",
#KnownAuthStatusCode.DENIED_DEVICE_MODEL: "Denied device model",
#KnownAuthStatusCode.RESET_STEP: "Reset step",
#KnownAuthStatusCode.NEED_PROTECTOR_AGREE: "Must agree to protector terms",
#KnownAuthStatusCode.ACCOUNT_RESTRICTED: "Account restricted",
##KnownAuthStatusCode.INVALID_STAGE_ERROR: "Same as KnownAuthStatusCode.AUTH_REQUIRED",
#KnownAuthStatusCode.UPGRADE_REQUIRED: "Upgrade required",
#KnownAuthStatusCode.VOICE_CALL_ONLY: "Voice call only",
#KnownAuthStatusCode.ACCESSIBILITY_ARS_ONLY: "Accessibility only",
#KnownAuthStatusCode.MIGRATION_FAILURE: "Migration failure",
#KnownAuthStatusCode.INVAILD_TOKEN: "Invalid token",
#KnownAuthStatusCode.UNDEFINED: "Undefined error",
#KnownDataStatusCode.SUCCESS: "Success",
#KnownDataStatusCode.INVALID_USER: "Invalid user",
#KnownDataStatusCode.CLIENT_ERROR: "Client error",
#KnownDataStatusCode.NOT_LOGON: "Not logged in",
#KnownDataStatusCode.INVALID_METHOD: "Invalid method",
#KnownDataStatusCode.INVALID_PARAMETER: "Invalid parameter",
#KnownDataStatusCode.INVALID_BODY: "Invalid body",
#KnownDataStatusCode.INVALID_HEADER: "Invalid header",
#KnownDataStatusCode.UNAUTHORIZED_CHAT_DELETE: "Unauthorized chat deletion",
#KnownDataStatusCode.MEDIA_SERVER_ERROR: "Media server error",
#KnownDataStatusCode.CHAT_SPAM_LIMIT: "Chat spam limit exceeded",
#KnownDataStatusCode.RESTRICTED_APP: "Restricted app",
#KnownDataStatusCode.LOGINLIST_CHATLIST_FAILED: "Login chat list failed",
#KnownDataStatusCode.MEDIA_NOT_FOUND: "Media not found",
#KnownDataStatusCode.MEDIA_THUMB_GEN_FAILED: "Could not generate media thumbnail",
#KnownDataStatusCode.UNSUPPORTED: "Unsupported",
#KnownDataStatusCode.PARTIAL: "Parial",
#KnownDataStatusCode.LINK_JOIN_TPS_EXCEEDED: "Link join TPS exceeded",
#KnownDataStatusCode.CHAT_SEND_RESTRICTED: "Chat send restricted",
#KnownDataStatusCode.CHANNEL_CREATE_TEMP_RESTRICTED: "Channel creation temporarily restricted",
#KnownDataStatusCode.CHANNEL_CREATE_RESTRICTED: "Channel creation restricted",
#KnownDataStatusCode.OPENLINK_UNAVAILABLE: "Openlink unavailable",
#KnownDataStatusCode.INVITE_COUNT_LIMITED: "Invite count limited",
#KnownDataStatusCode.OPENLINK_CREATE_RESTRICTED: "Openlink creation restricted",
#KnownDataStatusCode.INVALID_CHANNEL: "Invalid channel",
#KnownDataStatusCode.CHAT_BLOCKED_BY_FRIEND: "Blocked by friend",
#KnownDataStatusCode.NOT_CHATABLE_USER: "Non-chattable user",
#KnownDataStatusCode.GAME_MESSAGE_BLOCKED: "Game message blocked",
#KnownDataStatusCode.BLOCKED_IP: "Blocked IP",
#KnownDataStatusCode.BACKGROUND_LOGIN_BLOCKED: "Background login blocked",
#KnownDataStatusCode.OPERATION_DENIED: "Operation denied",
#KnownDataStatusCode.CHANNEL_USER_LIMITED: "Channel user limited",
#KnownDataStatusCode.TEMP_RESTRICTED: "Temporarily restricted",
#KnownDataStatusCode.WRITE_WHILE_BLOCKED: "Write while blocked",
#KnownDataStatusCode.OPENCHAT_REJOIN_REQUIRED: "Openchat rejoin required",
#KnownDataStatusCode.OPENCHAT_TIME_RESTRICTED: "Openchat time restricted",
KnownDataStatusCode.INVALID_ACCESS_TOKEN: InvalidAccessToken,
##KnownDataStatusCode.BLOCKED_ACCOUNT: "Same as KnownAuthStatusCode.ACCOUNT_RESTRICTED"
KnownDataStatusCode.AUTH_REQUIRED: AuthenticationRequired,
##KnownDataStatusCode.UPDATE_REQUIRED = "Same as KnownAuthStatusCode.UPGRADE_REQUIRED"
#KnownDataStatusCode.SERVER_UNDER_MAINTENANCE: "Server under maintenance",
401: InvalidAccessToken,
}