-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
509b88f
commit 618fce4
Showing
4 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,68 @@ | ||
class TPGalWSException(Exception): | ||
pass | ||
class AppError(): | ||
""" | ||
Represents error information returned by the server | ||
""" | ||
def __init__(self, code, message): | ||
self.code = code | ||
""" | ||
An integer which identifies an error | ||
""" | ||
self.message = message | ||
""" | ||
The actual error message | ||
""" | ||
|
||
class TPGalWSBlankResponse(Exception): | ||
pass | ||
|
||
class TPGalWSBaseResponseException(Exception): | ||
""" | ||
Exception used for succesful connections to the server but that for some reason didn't provide any result | ||
""" | ||
|
||
def __init__(self, message, response): | ||
|
||
super().__init__( | ||
f"HTTP --> {response.status_code}: {response.reason} || {message}") | ||
|
||
self.response = response | ||
""" | ||
The `requests.response` object of the failed request | ||
""" | ||
|
||
|
||
class TPGalWSAppException(TPGalWSBaseResponseException): | ||
""" | ||
Exception used when the server returns a JSON response with information about an error | ||
""" | ||
|
||
def __init__(self, response, data_out=None): | ||
self.data_out = data_out or response.json() | ||
""" | ||
`requests.response.json()` | ||
""" | ||
|
||
self.app_error = AppError(self.data_out.get( | ||
'code'), self.data_out.get('message')) | ||
""" | ||
`AppError` with more information about the cause of the error | ||
""" | ||
|
||
super().__init__( | ||
f"App --> {self.app_error.code}: {self.app_error.message}", response) | ||
|
||
|
||
class TPGalWSBlankResponse(TPGalWSBaseResponseException): | ||
""" | ||
Exception used when the server returns nothing (really, just nothing, `b''` if you know what I mean😉) | ||
""" | ||
|
||
def __init__(self, response): | ||
super().__init__("The API errored silently", response) | ||
|
||
|
||
class TPGalWSBadJsonException(TPGalWSBaseResponseException): | ||
""" | ||
Exception when the server returns something, but it isn't JSON-parseable | ||
""" | ||
|
||
def __init__(self, response): | ||
super().__init__("Bad JSON in response", response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters