Skip to content

Commit 0e58257

Browse files
committed
_register_error -> _server_origin_error, and unmark ServerNotReadyError
1 parent b70638b commit 0e58257

1 file changed

Lines changed: 43 additions & 44 deletions

File tree

brainframe/api/bf_errors.py

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"""Maps error kinds to their corresponding error type."""
66

77

8-
def _register_error(kind: Optional[str] = None):
8+
def _server_origin_error(kind: Optional[str] = None):
99
"""A class decorator. Registers the given class so that it will be used
1010
when an error with a kind equal to the class's name is provided as a
11-
response.
11+
response. Used only for Errors that can originate on the BrainFrame server.
1212
1313
:param kind: If provided, this class will be associated with this kind
1414
instead of using the class's name as the kind
@@ -47,7 +47,7 @@ def pretty_name(self):
4747
return s3
4848

4949

50-
@_register_error()
50+
@_server_origin_error()
5151
class UnknownError(BaseAPIError):
5252
"""Something unexpected happened. The server may be in an invalid state."""
5353

@@ -56,243 +56,242 @@ def __init__(self, description, status_code=None):
5656
self.status_code = status_code
5757

5858

59-
@_register_error()
59+
@_server_origin_error()
6060
class StreamConfigNotFoundError(BaseAPIError):
6161
"""A StreamConfiguration specified by the client could not be found."""
6262

6363

64-
@_register_error()
64+
@_server_origin_error()
6565
class ZoneNotFoundError(BaseAPIError):
6666
"""A Zone specified by the client could not be found."""
6767

6868

69-
@_register_error()
69+
@_server_origin_error()
7070
class PremisesNotFoundError(BaseAPIError):
7171
"""A Zone specified by the client could not be found."""
7272

7373

74-
@_register_error()
74+
@_server_origin_error()
7575
class ZoneNotDeletableError(BaseAPIError):
7676
"""A client tried to delete a default Zone"""
7777

7878

79-
@_register_error()
79+
@_server_origin_error()
8080
class AlertNotFoundError(BaseAPIError):
8181
"""An Alert specified by the client could not be found."""
8282

8383

84-
@_register_error()
84+
@_server_origin_error()
8585
class InvalidSyntaxError(BaseAPIError):
8686
"""The syntax of the request could not be parsed."""
8787

8888

89-
@_register_error()
89+
@_server_origin_error()
9090
class InvalidFormatError(BaseAPIError):
9191
"""The request was parsed, but some value within the request is invalid."""
9292

9393

94-
@_register_error("NotImplementedError")
94+
@_server_origin_error("NotImplementedError")
9595
class NotImplementedInAPIError(BaseAPIError):
9696
"""The client requested something that is not currently implemented."""
9797

9898

99-
@_register_error()
99+
@_server_origin_error()
100100
class StreamNotOpenedError(BaseAPIError):
101101
"""A stream failed to open when it was required to."""
102102

103103

104-
@_register_error()
104+
@_server_origin_error()
105105
class DuplicateStreamSourceError(BaseAPIError):
106106
"""There was an attempted to create a stream configuration with the same
107107
source as an existing one.
108108
"""
109109

110110

111-
@_register_error()
111+
@_server_origin_error()
112112
class DuplicateZoneNameError(BaseAPIError):
113113
"""There was an attempt to make a zone with the same name as another zone
114114
within the same stream.
115115
"""
116116

117117

118-
@_register_error()
118+
@_server_origin_error()
119119
class DuplicateIdentityNameError(BaseAPIError):
120120
"""There was an attempt to create a new identity with the same name as
121121
another identity.
122122
"""
123123

124124

125-
@_register_error()
125+
@_server_origin_error()
126126
class NoDetectorForClassError(BaseAPIError):
127127
"""There was an attempt to use a class name that is not detectable."""
128128

129129

130-
@_register_error()
130+
@_server_origin_error()
131131
class NoEncoderForClassError(BaseAPIError):
132132
"""There was an attempt to create an identity for a class that is not
133133
encodable.
134134
"""
135135

136136

137-
@_register_error()
137+
@_server_origin_error()
138138
class IdentityNotFoundError(BaseAPIError):
139139
"""An identity specified by the client could not be found."""
140140

141141

142-
@_register_error()
142+
@_server_origin_error()
143143
class ImageNotFoundForIdentityError(BaseAPIError):
144144
"""An image specified by the client could not be found for the specified
145145
identity.
146146
"""
147147

148148

149-
@_register_error()
149+
@_server_origin_error()
150150
class InvalidImageTypeError(BaseAPIError):
151151
"""An image could not be decoded by OpenCV"""
152152

153153

154-
@_register_error()
154+
@_server_origin_error()
155155
class AnalysisLimitExceededError(BaseAPIError):
156156
"""There was an attempt to start analysis on a stream, but the maximum
157157
amount of streams that may have analysis run on them at once has already
158158
been reached.
159159
"""
160160

161161

162-
@_register_error()
162+
@_server_origin_error()
163163
class NoDetectionsInImageError(BaseAPIError):
164164
"""There was an attempt to encode an image with no objects of the given
165165
class in the frame.
166166
"""
167167

168168

169-
@_register_error()
169+
@_server_origin_error()
170170
class TooManyDetectionsInImageError(BaseAPIError):
171171
"""There was an attempt to encode an image with more than one object of the
172172
given class in the frame, causing ambiguity on which one to encode.
173173
"""
174174

175175

176-
@_register_error()
176+
@_server_origin_error()
177177
class ImageAlreadyEncodedError(BaseAPIError):
178178
"""There was an attempt to encode an image that has already been encoded
179179
for a given identity and a given class.
180180
"""
181181

182182

183-
@_register_error()
183+
@_server_origin_error()
184184
class DuplicateVectorError(BaseAPIError):
185185
"""There was an attempt to add a vector that already exists for the given
186186
identity and class.
187187
"""
188188

189189

190-
@_register_error()
190+
@_server_origin_error()
191191
class FrameNotFoundForAlertError(BaseAPIError):
192192
"""There was an attempt to get a frame for an alert that has no frame."""
193193

194194

195-
@_register_error("PluginNotFoundError")
195+
@_server_origin_error("PluginNotFoundError")
196196
class CapsuleNotFoundError(BaseAPIError):
197197
"""There was an attempt to reference a capsule that does not exist."""
198198

199199

200-
@_register_error("InvalidPluginOptionError")
200+
@_server_origin_error("InvalidPluginOptionError")
201201
class InvalidCapsuleOptionError(BaseAPIError):
202202
"""The provided capsule options do not work for the given capsule. This
203203
could be because the option does not exist or the value for that option
204204
doesn't fit the constraints.
205205
"""
206206

207207

208-
@_register_error()
208+
@_server_origin_error()
209209
class StorageNotFoundError(BaseAPIError):
210210
"""There was an attempt to access a storage object that does not exist."""
211211

212212

213-
@_register_error()
213+
@_server_origin_error()
214214
class ZoneAlarmNotFoundError(BaseAPIError):
215215
"""There was an attempt to access a zone alarm that does not exist."""
216216

217217

218-
@_register_error()
218+
@_server_origin_error()
219219
class InvalidRuntimeOptionError(BaseAPIError):
220220
"""There was an attempt to set a runtime option that is not supported or is
221221
of the wrong type.
222222
"""
223223

224224

225-
@_register_error()
225+
@_server_origin_error()
226226
class EncodingNotFoundError(BaseAPIError):
227227
"""There was an attempt to access an encoding that does not exist."""
228228

229229

230-
@_register_error()
230+
@_server_origin_error()
231231
class UnauthorizedError(BaseAPIError):
232232
"""There was an attempt to access the API without proper authorization."""
233233

234234

235-
@_register_error()
235+
@_server_origin_error()
236236
class InvalidSessionError(BaseAPIError):
237237
"""There was an attempt to access the API with an invalid session ID,
238238
either because the session expired or no session with that ID has ever
239239
existed. The client should authenticate again to get a new session.
240240
"""
241241

242242

243-
@_register_error()
243+
@_server_origin_error()
244244
class VectorTooLongError(BaseAPIError):
245245
"""The provided encoding vector is longer than the maximum allowed
246246
length.
247247
"""
248248

249249

250-
@_register_error()
250+
@_server_origin_error()
251251
class UserNotFoundError(BaseAPIError):
252252
"""There was an attempt to access a user by ID that does not exist."""
253253

254254

255-
@_register_error()
255+
@_server_origin_error()
256256
class InsufficientRoleError(BaseAPIError):
257257
"""A user attempted an operation that they don't have permission to do."""
258258

259259

260-
@_register_error()
260+
@_server_origin_error()
261261
class DuplicateUsernameError(BaseAPIError):
262262
"""The requested username already exists."""
263263

264264

265-
@_register_error()
265+
@_server_origin_error()
266266
class AdminMustExistError(BaseAPIError):
267267
"""There was an attempt to delete the only remaining admin account."""
268268

269269

270-
@_register_error()
270+
@_server_origin_error()
271271
class LicenseRequiredError(BaseAPIError):
272272
"""There was an attempt to access a resource that requires an active
273273
license while no valid license is loaded.
274274
"""
275275

276276

277-
@_register_error()
277+
@_server_origin_error()
278278
class LicenseExpiredError(BaseAPIError):
279279
"""There was an attempt to upload a license that is expired."""
280280

281281

282-
@_register_error()
282+
@_server_origin_error()
283283
class LicenseInvalidError(BaseAPIError):
284284
"""There was an attempt to upload a license that is in an invalid format.
285285
"""
286286

287287

288-
@_register_error()
288+
@_server_origin_error()
289289
class RemoteConnectionError(BaseAPIError):
290290
"""The server encountered an error while connecting to a remote resource
291291
that is required for the requested operation.
292292
"""
293293

294294

295-
@_register_error()
296295
class ServerNotReadyError(BaseAPIError):
297296
"""The client was able to communicate with the server, but the server had
298297
not completed startup or was in an invalid state"""

0 commit comments

Comments
 (0)