forked from smiley/steamapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
121 lines (94 loc) · 3.21 KB
/
errors.py
File metadata and controls
121 lines (94 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
__author__ = 'SmileyBarry'
from .decorators import debug
class APIException(Exception):
"""
Base class for all API exceptions.
"""
pass
class AccessException(APIException):
"""
You are attempting to query an object that you have no permission to query. (E.g.: private user,
hidden screenshot, etc.)
"""
pass
class APIUserError(APIException):
"""
An API error caused by a user error, like wrong data or just empty results for a query.
"""
pass
class UserNotFoundError(APIUserError):
"""
The specified user was not found on the Steam Community. (Bad vanity URL? Non-existent ID?)
"""
pass
class APIError(APIException):
"""
An API error signifies a problem with the server, a temporary issue or some other easily-repairable
problem.
"""
pass
class APIFailure(APIException):
"""
An API failure signifies a problem with your request (e.g.: invalid API), a problem with your data,
or any error that resulted from improper use.
"""
pass
class APIBadCall(APIFailure):
"""
Your API call doesn't match the API's specification. Check your arguments, service name, command &
version.
"""
pass
class APINotFound(APIFailure):
"""
The API you tried to call does not exist. (404)
"""
pass
class APIUnauthorized(APIFailure):
"""
The API you've attempted to call either requires a key, or your key has insufficient permissions.
If you're requesting user details, make sure their privacy level permits you to do so, or that you've
properly authorised said user. (401)
"""
pass
class APIKeyRequired(APIFailure):
"""
This API requires an API key to call and does not support anonymous requests.
"""
pass
class APIPrivate(APIFailure):
"""
The API you're trying to call requires a privileged API key. Your existing key is not allowed to call this.
"""
class APIConfigurationError(APIFailure):
"""
There's either no APIConnection defined, or the parameters given to "APIConnection" or "APIInterface" are
invalid.
"""
pass
def check(response):
"""
:type response: requests.Response
"""
if response.status_code // 100 == 4:
if response.status_code == 404:
raise APINotFound(
"The function or service you tried to call does not exist.")
elif response.status_code == 401:
raise APIUnauthorized("This API is not accessible to you.")
elif response.status_code == 403:
if '?key=' in response.request.url or '&key=' in response.request.url:
raise APIPrivate(
"You have no permission to use this API, or your key may be invalid.")
else:
raise APIKeyRequired("This API requires a key to call.")
elif response.status_code == 400:
raise APIBadCall(
"The parameters you sent didn't match this API's requirements.")
else:
raise APIFailure(
"Something is wrong with your configuration, parameters or environment.")
elif response.status_code // 100 == 5:
raise APIError("The API server has encountered an unknown error.")
else:
return