forked from FOSS/Steam-Panel
v 3.0.3
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
from .codes import STEAM_ERROR_CODES
|
||||
from .exceptions import (
|
||||
SteamError,
|
||||
UnknownSteamError,
|
||||
custom_error_exception,
|
||||
)
|
||||
from .response import check_steam_error
|
||||
|
||||
|
||||
__all__ = [
|
||||
'check_steam_error',
|
||||
'SteamError',
|
||||
'UnknownSteamError',
|
||||
'STEAM_ERROR_CODES',
|
||||
'custom_error_exception',
|
||||
]
|
||||
@@ -0,0 +1,125 @@
|
||||
STEAM_ERROR_CODES = {
|
||||
1: 'OK',
|
||||
2: 'Fail',
|
||||
3: 'NoConnection',
|
||||
4: 'NoConnectionRetry',
|
||||
5: 'InvalidPassword',
|
||||
6: 'LoggedInElsewhere',
|
||||
7: 'InvalidProtocolVer',
|
||||
8: 'InvalidParam',
|
||||
9: 'FileNotFound',
|
||||
10: 'Busy',
|
||||
11: 'InvalidState',
|
||||
12: 'InvalidName',
|
||||
13: 'InvalidEmail',
|
||||
14: 'DuplicateName',
|
||||
15: 'AccessDenied',
|
||||
16: 'Timeout',
|
||||
17: 'Banned',
|
||||
18: 'AccountNotFound',
|
||||
19: 'InvalidSteamID',
|
||||
20: 'ServiceUnavailable',
|
||||
21: 'NotLoggedOn',
|
||||
22: 'Pending',
|
||||
23: 'EncryptionFailure',
|
||||
24: 'InsufficientPrivilege',
|
||||
25: 'LimitExceeded',
|
||||
26: 'Revoked',
|
||||
27: 'Expired',
|
||||
28: 'AlreadyRedeemed',
|
||||
29: 'DuplicateRequest',
|
||||
30: 'AlreadyOwned',
|
||||
31: 'IPNotFound',
|
||||
32: 'PersistFailed',
|
||||
33: 'LockingFailed',
|
||||
34: 'LogonSessionReplaced',
|
||||
35: 'ConnectFailed',
|
||||
36: 'HandshakeFailed',
|
||||
37: 'IOFailure',
|
||||
38: 'RemoteDisconnect',
|
||||
39: 'ShoppingCartNotFound',
|
||||
40: 'Blocked',
|
||||
41: 'Ignored',
|
||||
42: 'NoMatch',
|
||||
43: 'AccountDisabled',
|
||||
44: 'ServiceReadOnly',
|
||||
45: 'AccountNotFeatured',
|
||||
46: 'AdministratorOK',
|
||||
47: 'ContentVersion',
|
||||
48: 'TryAnotherCM',
|
||||
49: 'PasswordRequiredToKickSession',
|
||||
50: 'AlreadyLoggedInElsewhere',
|
||||
51: 'Suspended',
|
||||
52: 'Cancelled',
|
||||
53: 'DataCorruption',
|
||||
54: 'DiskFull',
|
||||
55: 'RemoteCallFailed',
|
||||
56: 'PasswordUnset',
|
||||
57: 'ExternalAccountUnlinked',
|
||||
58: 'PSNTicketInvalid',
|
||||
59: 'ExternalAccountAlreadyLinked',
|
||||
60: 'RemoteFileConflict',
|
||||
61: 'IllegalPassword',
|
||||
62: 'SameAsPreviousValue',
|
||||
63: 'AccountLogonDenied',
|
||||
64: 'CannotUseOldPassword',
|
||||
65: 'InvalidLoginAuthCode',
|
||||
66: 'AccountLogonDeniedNoMail',
|
||||
67: 'HardwareNotCapableOfIPT',
|
||||
68: 'IPTInitError',
|
||||
69: 'ParentalControlRestricted',
|
||||
70: 'FacebookQueryError',
|
||||
71: 'ExpiredLoginAuthCode',
|
||||
72: 'IPLoginRestrictionFailed',
|
||||
73: 'AccountLockedDown',
|
||||
74: 'AccountLogonDeniedVerifiedEmailRequired',
|
||||
75: 'NoMatchingURL',
|
||||
76: 'BadResponse',
|
||||
77: 'RequirePasswordReEntry',
|
||||
78: 'ValueOutOfRange',
|
||||
79: 'UnexpectedError',
|
||||
80: 'Disabled',
|
||||
81: 'InvalidCEGSubmission',
|
||||
82: 'RestrictedDevice',
|
||||
83: 'RegionLocked',
|
||||
84: 'RateLimitExceeded',
|
||||
85: 'AccountLoginDeniedNeedTwoFactor',
|
||||
86: 'ItemDeleted',
|
||||
87: 'AccountLoginDeniedThrottle',
|
||||
88: 'TwoFactorCodeMismatch',
|
||||
89: 'TwoFactorActivationCodeMismatch',
|
||||
90: 'AccountAssociatedToMultiplePartners',
|
||||
91: 'NotModified',
|
||||
92: 'NoMobileDevice',
|
||||
93: 'TimeNotSynced',
|
||||
94: 'SmsCodeFailed',
|
||||
95: 'AccountLimitExceeded',
|
||||
96: 'AccountActivityLimitExceeded',
|
||||
97: 'PhoneActivityLimitExceeded',
|
||||
98: 'RefundToWallet',
|
||||
99: 'EmailSendFailure',
|
||||
100: 'NotSettled',
|
||||
101: 'NeedCaptcha',
|
||||
102: 'GSLTDenied',
|
||||
103: 'GSOwnerDenied',
|
||||
104: 'InvalidItemType',
|
||||
105: 'IPBanned',
|
||||
106: 'GSLTExpired',
|
||||
107: 'InsufficientFunds',
|
||||
108: 'TooManyPending',
|
||||
109: 'NoSiteLicensesFound',
|
||||
110: 'WGNetworkSendExceeded',
|
||||
111: 'AccountNotFriends',
|
||||
112: 'LimitedUserAccount',
|
||||
113: 'CantRemoveItem',
|
||||
114: 'AccountDeleted',
|
||||
115: 'ExistingUserCancelledLicense',
|
||||
116: 'CommunityCooldown',
|
||||
117: 'NoLauncherSpecified',
|
||||
118: 'MustAgreeToSSA',
|
||||
119: 'LauncherMigrated',
|
||||
120: 'SteamRealmMismatch',
|
||||
121: 'InvalidSignature',
|
||||
122: 'ParseFailure',
|
||||
123: 'NoVerifiedPhone',
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import (
|
||||
Dict,
|
||||
Optional,
|
||||
Type,
|
||||
)
|
||||
|
||||
from .codes import STEAM_ERROR_CODES
|
||||
|
||||
|
||||
class SteamError(Exception):
|
||||
|
||||
def __init__(self, error_code: int, error_msg: Optional[str] = None):
|
||||
self.error_code = error_code
|
||||
self.error_msg = error_msg
|
||||
|
||||
def __str__(self) -> str:
|
||||
return str({
|
||||
'error': STEAM_ERROR_CODES.get(self.error_code, self.error_code),
|
||||
'msg': self.error_msg,
|
||||
'code': self.error_code,
|
||||
})
|
||||
|
||||
|
||||
class UnknownSteamError(SteamError):
|
||||
...
|
||||
|
||||
|
||||
_CUSTOM_ERROR_EXCEPTIONS: Dict[int, Type[SteamError]] = {}
|
||||
|
||||
|
||||
def custom_error_exception(errors: Dict[int, Type[SteamError]]) -> None:
|
||||
global _CUSTOM_ERROR_EXCEPTIONS
|
||||
if not isinstance(errors, dict):
|
||||
raise TypeError('The error argument should be dict')
|
||||
|
||||
for _error, _exception in errors.items():
|
||||
if not isinstance(_error, int):
|
||||
raise TypeError('Error should be an integer')
|
||||
if not isinstance(_exception, type) or not issubclass(_exception, SteamError):
|
||||
raise TypeError('Exception should be inherited from SteamError')
|
||||
if _error not in STEAM_ERROR_CODES:
|
||||
raise TypeError(f'Unknown error code {_error}')
|
||||
_CUSTOM_ERROR_EXCEPTIONS[_error] = _exception
|
||||
@@ -0,0 +1,18 @@
|
||||
from typing import Optional
|
||||
|
||||
from .codes import STEAM_ERROR_CODES
|
||||
from .exceptions import (
|
||||
_CUSTOM_ERROR_EXCEPTIONS,
|
||||
SteamError,
|
||||
UnknownSteamError,
|
||||
)
|
||||
|
||||
|
||||
def check_steam_error(error: int, error_msg: Optional[str] = None) -> None:
|
||||
if error in (1, 22):
|
||||
return
|
||||
if error in _CUSTOM_ERROR_EXCEPTIONS:
|
||||
raise _CUSTOM_ERROR_EXCEPTIONS[error](error, error_msg)
|
||||
if error in STEAM_ERROR_CODES:
|
||||
raise SteamError(error_code=error, error_msg=error_msg)
|
||||
raise UnknownSteamError(error_code=error, error_msg=error_msg)
|
||||
Reference in New Issue
Block a user