-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvws_exceptions.py
More file actions
204 lines (155 loc) · 5.46 KB
/
vws_exceptions.py
File metadata and controls
204 lines (155 loc) · 5.46 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"""
Exception raised when Vuforia returns a response with a result code
matching
one of those documented at
https://developer.vuforia.com/library/web-api/cloud-targets-web-services-
api#result-codes.
"""
import json
from urllib.parse import urlparse
from beartype import beartype
from vws.exceptions.base_exceptions import VWSError
@beartype
class UnknownTargetError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'UnknownTarget'.
"""
@property
def target_id(self) -> str:
"""The unknown target ID."""
path = urlparse(url=self.response.url).path
# Every HTTP path which can raise this error has the target ID as the
# second path segment, e.g. `/something/{target_id}` or
# `/something/{target_id}/more`.
return path.split(sep="/")[2]
@beartype
class FailError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'Fail'.
"""
@beartype
class BadImageError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'BadImage'.
"""
@beartype
class AuthenticationFailureError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'AuthenticationFailure'.
"""
# See https://github.com/VWS-Python/vws-python/issues/822.
@beartype
class RequestQuotaReachedError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'RequestQuotaReached'.
"""
@beartype
class TargetStatusProcessingError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'TargetStatusProcessing'.
"""
@property
def target_id(self) -> str:
"""The processing target ID."""
path = urlparse(url=self.response.url).path
# Every HTTP path which can raise this error has the target ID as the
# second path segment, e.g. `/something/{target_id}` or
# `/something/{target_id}/more`.
return path.split(sep="/")[2]
# This is not simulated by the mock.
@beartype
class DateRangeError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'DateRangeError'.
"""
# This is not simulated by the mock.
@beartype
class TargetQuotaReachedError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'TargetQuotaReached'.
"""
# This is not simulated by the mock.
@beartype
class ProjectSuspendedError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'ProjectSuspended'.
"""
# This is not simulated by the mock.
@beartype
class ProjectHasNoAPIAccessError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'ProjectHasNoAPIAccess'.
"""
@beartype
class ProjectInactiveError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'ProjectInactive'.
"""
@beartype
class MetadataTooLargeError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'MetadataTooLarge'.
"""
@beartype
class RequestTimeTooSkewedError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'RequestTimeTooSkewed'.
"""
@beartype
class TargetNameExistError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'TargetNameExist'.
"""
@property
def target_name(self) -> str:
"""The target name which already exists."""
response_body = self.response.request_body or b""
request_json = json.loads(s=response_body)
return str(object=request_json["name"])
@beartype
class ImageTooLargeError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'ImageTooLarge'.
"""
@beartype
class TargetStatusNotSuccessError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
'TargetStatusNotSuccess'.
"""
@property
def target_id(self) -> str:
"""The unknown target ID."""
path = urlparse(url=self.response.url).path
# Every HTTP path which can raise this error has the target ID as the
# second path segment, e.g. `/something/{target_id}` or
# `/something/{target_id}/more`.
return path.split(sep="/")[2]
@beartype
class TooManyRequestsError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
'TooManyRequests'.
"""
# This is not simulated by client code because the accept parameter uses
# the VuMarkAccept enum, which only allows valid values.
@beartype
class InvalidAcceptHeaderError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
``InvalidAcceptHeader``.
"""
@beartype
class InvalidInstanceIdError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
``InvalidInstanceId``.
"""
# This is not simulated by client code because the request body
# is always valid JSON when using this client.
@beartype
class BadRequestError(VWSError): # pragma: no cover
"""Exception raised when Vuforia returns a response with a result code
``BadRequest``.
"""
@beartype
class InvalidTargetTypeError(VWSError):
"""Exception raised when Vuforia returns a response with a result code
``InvalidTargetType``.
"""