mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-06-12 15:54:42 -04:00
SDK-2525: Refactor errors
This commit is contained in:
73
galaxy/api/errors.py
Normal file
73
galaxy/api/errors.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from galaxy.api.jsonrpc import ApplicationError
|
||||
|
||||
class UnknownError(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(0, "Unknown error", data)
|
||||
|
||||
class InvalidCredentials(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(100, "Invalid credentials", data)
|
||||
|
||||
class NetworkError(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(101, "Network error", data)
|
||||
|
||||
class LoggedInElsewhere(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(102, "Logged in elsewhere", data)
|
||||
|
||||
class ProtocolError(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(103, "Protocol error", data)
|
||||
|
||||
class BackendNotAvailable(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(104, "Backend not available", data)
|
||||
|
||||
class BackendTimeout(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(105, "Backend timed out", data)
|
||||
|
||||
class BackendError(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(106, "Backend error", data)
|
||||
|
||||
class TemporaryBlocked(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(107, "Temporary blocked", data)
|
||||
|
||||
class Banned(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(108, "Banned", data)
|
||||
|
||||
class AccessDenied(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(109, "Access denied", data)
|
||||
|
||||
class ParentalControlBlock(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(110, "Parental control block", data)
|
||||
|
||||
class DeviceBlocked(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(111, "Device blocked", data)
|
||||
|
||||
class RegionBlocked(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(112, "Region blocked", data)
|
||||
|
||||
class FailedParsingManifest(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(200, "Failed parsing manifest", data)
|
||||
|
||||
class TooManyMessagesSent(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(300, "Too many messages sent", data)
|
||||
|
||||
class IncoherentLastMessage(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(400, "Different last message id on backend", data)
|
||||
|
||||
class MessageNotFound(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(500, "Message not found", data)
|
||||
@@ -26,9 +26,19 @@ class InvalidParams(JsonRpcError):
|
||||
def __init__(self):
|
||||
super().__init__(-32601, "Invalid params")
|
||||
|
||||
class Timeout(JsonRpcError):
|
||||
def __init__(self):
|
||||
super().__init__(-32000, "Method timed out")
|
||||
|
||||
class Aborted(JsonRpcError):
|
||||
def __init__(self):
|
||||
super().__init__(-32001, "Method aborted")
|
||||
|
||||
class ApplicationError(JsonRpcError):
|
||||
def __init__(self, data):
|
||||
super().__init__(-32003, "Custom error", data)
|
||||
def __init__(self, code, message, data):
|
||||
if code >= -32768 and code <= -32000:
|
||||
raise ValueError("The error code in reserved range")
|
||||
super().__init__(code, message, data)
|
||||
|
||||
Request = namedtuple("Request", ["method", "params", "id"], defaults=[{}, None])
|
||||
Method = namedtuple("Method", ["callback", "internal"])
|
||||
@@ -172,10 +182,13 @@ class Server():
|
||||
"id": request_id,
|
||||
"error": {
|
||||
"code": error.code,
|
||||
"message": error.message,
|
||||
"data": error.data
|
||||
"message": error.message
|
||||
}
|
||||
}
|
||||
|
||||
if error.data is not None:
|
||||
response["error"]["data"] = error.data
|
||||
|
||||
self._send(response)
|
||||
|
||||
class NotificationClient():
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
from galaxy.api.jsonrpc import ApplicationError
|
||||
from galaxy.api.consts import LocalGameState, PresenceState
|
||||
|
||||
@dataclass
|
||||
@@ -9,14 +8,6 @@ class Authentication():
|
||||
user_id: str
|
||||
user_name: str
|
||||
|
||||
class LoginError(ApplicationError):
|
||||
def __init__(self, current_step, reason):
|
||||
data = {
|
||||
"current_step": current_step,
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class LicenseInfo():
|
||||
license_type: str
|
||||
@@ -35,37 +26,16 @@ class Game():
|
||||
dlcs: List[Dlc]
|
||||
license_info: LicenseInfo
|
||||
|
||||
class GetGamesError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class Achievement():
|
||||
achievement_id: str
|
||||
unlock_time: int
|
||||
|
||||
class GetAchievementsError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class LocalGame():
|
||||
game_id: str
|
||||
local_game_state: LocalGameState
|
||||
|
||||
class GetLocalGamesError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class Presence():
|
||||
presence_state: PresenceState
|
||||
@@ -80,47 +50,12 @@ class UserInfo():
|
||||
avatar_url: str
|
||||
presence: Presence
|
||||
|
||||
class GetFriendsError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
class GetUsersError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
class SendMessageError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
class MarkAsReadError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class Room():
|
||||
room_id: str
|
||||
unread_message_count: int
|
||||
last_message_id: str
|
||||
|
||||
class GetRoomsError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class Message():
|
||||
message_id: str
|
||||
@@ -128,22 +63,8 @@ class Message():
|
||||
sent_time: int
|
||||
message_text: str
|
||||
|
||||
class GetRoomHistoryError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
|
||||
@dataclass
|
||||
class GameTime():
|
||||
game_id: str
|
||||
time_played: int
|
||||
last_played_time: int
|
||||
|
||||
class GetGameTimeError(ApplicationError):
|
||||
def __init__(self, reason):
|
||||
data = {
|
||||
"reason": reason
|
||||
}
|
||||
super().__init__(data)
|
||||
Reference in New Issue
Block a user