Skip to content

Commit 2a6108a

Browse files
Update raise errors.
1 parent e12148a commit 2a6108a

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/handlers/api.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get(self):
6767
# raising HTTPError will cause headers to be emptied
6868
self.finish()
6969
else:
70-
raise HTTPError(403)
70+
raise HTTPError(status_code=403)
7171

7272

7373
class LoginHandler(AuthHandler):
@@ -112,7 +112,7 @@ class ValidateHandler(BaseHandler):
112112

113113
async def get(self):
114114
if self.request.body:
115-
raise HTTPError(400, reason="GET takes no request body.")
115+
raise HTTPError(status_code=400, log_message="GET takes no request body.")
116116

117117
raw = await self.download(self.args.url)
118118
self.validate(raw)
@@ -129,7 +129,7 @@ async def download(self, url):
129129
try:
130130
file = await download_async(url)
131131
except DownloadError as err:
132-
raise HTTPError(400, reason=str(err))
132+
raise HTTPError(status_code=400, log_message=str(err))
133133
else: # other file info irrelevant for validation
134134
return file.raw
135135

@@ -140,7 +140,7 @@ def validate(self, raw):
140140
smartapi.validate()
141141

142142
except (ControllerError, AssertionError) as err:
143-
raise HTTPError(400, reason=str(err))
143+
raise HTTPError(status_code=400, log_message=str(err))
144144
else:
145145
self.finish({"success": True, "details": f"valid SmartAPI ({smartapi.version}) metadata."})
146146

@@ -164,19 +164,19 @@ async def post(self):
164164
"""
165165

166166
if SmartAPI.find(self.args.url, "url"):
167-
raise HTTPError(409)
167+
raise HTTPError(status_code=409)
168168

169169
try:
170170
file = await download_async(self.args.url)
171171
except DownloadError as err:
172-
raise HTTPError(400, reason=str(err)) from err
172+
raise HTTPError(status_code=400, log_message=str(err)) from err
173173

174174
try:
175175
smartapi = SmartAPI(self.args.url)
176176
smartapi.raw = file.raw
177177
smartapi.validate()
178178
except (ControllerError, AssertionError) as err:
179-
raise HTTPError(400, reason=str(err)) from err
179+
raise HTTPError(status_code=400, log_message=str(err)) from err
180180

181181
if self.args.dryrun:
182182
raise Finish({"success": True, "details": f"[Dryrun] Valid {smartapi.version} Metadata"})
@@ -186,7 +186,7 @@ async def post(self):
186186
smartapi.refresh(file) # populate webdoc meta
187187
_id = smartapi.save()
188188
except ControllerError as err:
189-
raise HTTPError(400, reason=str(err)) from err
189+
raise HTTPError(status_code=400, log_message=str(err)) from err
190190
else:
191191
self.finish({"success": True, "_id": _id})
192192
await self._notify(smartapi)
@@ -251,21 +251,21 @@ async def put(self, _id):
251251
try:
252252
smartapi = SmartAPI.get(_id)
253253
except NotFoundError:
254-
raise HTTPError(404)
254+
raise HTTPError(status_code=404)
255255

256256
if smartapi.username != self.current_user["login"]:
257-
raise HTTPError(403)
257+
raise HTTPError(status_code=403)
258258

259259
if self.args.slug is not None:
260260
if self.args.slug in {"api"}: # reserved
261-
raise HTTPError(400, reason="slug is reserved")
261+
raise HTTPError(status_code=400, log_message="slug is reserved")
262262

263263
try: # update slug
264264
smartapi.slug = self.args.slug or None
265265
smartapi.save()
266266

267267
except (ControllerError, ValueError) as err:
268-
raise HTTPError(400, reason=str(err)) from err
268+
raise HTTPError(status_code=400, log_message=str(err)) from err
269269

270270
self.finish({"success": True})
271271

@@ -291,15 +291,15 @@ def delete(self, _id):
291291
try:
292292
smartapi = SmartAPI.get(_id)
293293
except NotFoundError:
294-
raise HTTPError(404)
294+
raise HTTPError(status_code=404)
295295

296296
if smartapi.username != self.current_user["login"]:
297-
raise HTTPError(403)
297+
raise HTTPError(status_code=403)
298298

299299
try:
300300
_id = smartapi.delete()
301301
except ControllerError as err:
302-
raise HTTPError(400, reason=str(err)) from err
302+
raise HTTPError(status_code=400, log_message=str(err)) from err
303303

304304
self.finish({"success": True, "_id": _id})
305305

@@ -345,41 +345,41 @@ class UptimeHandler(BaseHandler):
345345
@github_authenticated
346346
def get(self):
347347
if self.request.body:
348-
raise HTTPError(400, reason="GET takes no request body.")
348+
raise HTTPError(status_code=400, log_message="GET takes no request body.")
349349

350350
if self.args.id:
351351
try:
352352
smartapi = SmartAPI.get(self.args.id)
353353
if smartapi.username != self.current_user["login"]:
354-
raise HTTPError(403)
354+
raise HTTPError(status_code=403)
355355
status = smartapi.check()
356356
smartapi.save()
357357
except NotFoundError:
358-
raise HTTPError(404)
358+
raise HTTPError(status_code=404)
359359
except (ControllerError, AssertionError) as err:
360-
raise HTTPError(400, reason=str(err))
360+
raise HTTPError(status_code=400, log_message=str(err))
361361
else:
362362
self.finish({"success": True, "details": status})
363363
else:
364-
raise HTTPError(400, reason="Missing required parameter: id")
364+
raise HTTPError(status_code=400, log_message="Missing required parameter: id")
365365

366366
@github_authenticated
367367
def post(self):
368368
if self.args.id:
369369
try:
370370
smartapi = SmartAPI.get(self.args.id)
371371
if smartapi.username != self.current_user["login"]:
372-
raise HTTPError(403)
372+
raise HTTPError(status_code=403)
373373
status = smartapi.check()
374374
smartapi.save()
375375
except NotFoundError:
376-
raise HTTPError(404)
376+
raise HTTPError(status_code=404)
377377
except (ControllerError, AssertionError) as err:
378-
raise HTTPError(400, reason=str(err))
378+
raise HTTPError(status_code=400, log_message=str(err))
379379
else:
380380
self.finish({"success": True, "details": status})
381381
else:
382-
raise HTTPError(400, reason="Missing required form field: id")
382+
raise HTTPError(status_code=400, log_message="Missing required form field: id")
383383

384384

385385
class MetaKGQueryHandler(QueryHandler):

0 commit comments

Comments
 (0)