17
17
from controller .exceptions import ControllerError , NotFoundError
18
18
from pipeline import MetaKGQueryPipeline
19
19
from utils .downloader import DownloadError , download_async
20
+ from utils .http_error import SmartAPIHTTPError
20
21
from utils .metakg .export import edges2graphml
21
22
from utils .metakg .path_finder import MetaKGPathFinder
22
23
from utils .metakg .cytoscape_formatter import CytoscapeDataFormatter
@@ -67,7 +68,7 @@ def get(self):
67
68
# raising HTTPError will cause headers to be emptied
68
69
self .finish ()
69
70
else :
70
- raise HTTPError (403 )
71
+ raise HTTPError (status_code = 403 )
71
72
72
73
73
74
class LoginHandler (AuthHandler ):
@@ -112,7 +113,7 @@ class ValidateHandler(BaseHandler):
112
113
113
114
async def get (self ):
114
115
if self .request .body :
115
- raise HTTPError (400 , reason = "GET takes no request body." )
116
+ raise HTTPError (status_code = 400 , reason = "GET takes no request body." )
116
117
117
118
raw = await self .download (self .args .url )
118
119
self .validate (raw )
@@ -138,9 +139,8 @@ def validate(self, raw):
138
139
smartapi = SmartAPI (SmartAPI .VALIDATION_ONLY )
139
140
smartapi .raw = raw
140
141
smartapi .validate ()
141
-
142
142
except (ControllerError , AssertionError ) as err :
143
- raise HTTPError (400 , reason = str (err ))
143
+ raise SmartAPIHTTPError (400 , reason = str (err ))
144
144
else :
145
145
self .finish ({"success" : True , "details" : f"valid SmartAPI ({ smartapi .version } ) metadata." })
146
146
@@ -164,19 +164,19 @@ async def post(self):
164
164
"""
165
165
166
166
if SmartAPI .find (self .args .url , "url" ):
167
- raise HTTPError (409 )
167
+ raise HTTPError (status_code = 409 )
168
168
169
169
try :
170
170
file = await download_async (self .args .url )
171
171
except DownloadError as err :
172
- raise HTTPError (400 , reason = str (err )) from err
172
+ raise HTTPError (status_code = 400 , reason = str (err )) from err
173
173
174
174
try :
175
175
smartapi = SmartAPI (self .args .url )
176
176
smartapi .raw = file .raw
177
177
smartapi .validate ()
178
178
except (ControllerError , AssertionError ) as err :
179
- raise HTTPError (400 , reason = str (err )) from err
179
+ raise HTTPError (status_code = 400 , reason = str (err )) from err
180
180
181
181
if self .args .dryrun :
182
182
raise Finish ({"success" : True , "details" : f"[Dryrun] Valid { smartapi .version } Metadata" })
@@ -186,7 +186,7 @@ async def post(self):
186
186
smartapi .refresh (file ) # populate webdoc meta
187
187
_id = smartapi .save ()
188
188
except ControllerError as err :
189
- raise HTTPError (400 , reason = str (err )) from err
189
+ raise HTTPError (status_code = 400 , reason = str (err )) from err
190
190
else :
191
191
self .finish ({"success" : True , "_id" : _id })
192
192
await self ._notify (smartapi )
@@ -251,21 +251,21 @@ async def put(self, _id):
251
251
try :
252
252
smartapi = SmartAPI .get (_id )
253
253
except NotFoundError :
254
- raise HTTPError (404 )
254
+ raise HTTPError (status_code = 404 )
255
255
256
256
if smartapi .username != self .current_user ["login" ]:
257
- raise HTTPError (403 )
257
+ raise HTTPError (status_code = 403 )
258
258
259
259
if self .args .slug is not None :
260
260
if self .args .slug in {"api" }: # reserved
261
- raise HTTPError (400 , reason = "slug is reserved" )
261
+ raise HTTPError (status_code = 400 , reason = "slug is reserved" )
262
262
263
263
try : # update slug
264
264
smartapi .slug = self .args .slug or None
265
265
smartapi .save ()
266
266
267
267
except (ControllerError , ValueError ) as err :
268
- raise HTTPError (400 , reason = str (err )) from err
268
+ raise HTTPError (status_code = 400 , reason = str (err )) from err
269
269
270
270
self .finish ({"success" : True })
271
271
@@ -291,15 +291,15 @@ def delete(self, _id):
291
291
try :
292
292
smartapi = SmartAPI .get (_id )
293
293
except NotFoundError :
294
- raise HTTPError (404 )
294
+ raise HTTPError (status_code = 404 )
295
295
296
296
if smartapi .username != self .current_user ["login" ]:
297
- raise HTTPError (403 )
297
+ raise HTTPError (status_code = 403 )
298
298
299
299
try :
300
300
_id = smartapi .delete ()
301
301
except ControllerError as err :
302
- raise HTTPError (400 , reason = str (err )) from err
302
+ raise HTTPError (status_code = 400 , reason = str (err )) from err
303
303
304
304
self .finish ({"success" : True , "_id" : _id })
305
305
@@ -345,41 +345,41 @@ class UptimeHandler(BaseHandler):
345
345
@github_authenticated
346
346
def get (self ):
347
347
if self .request .body :
348
- raise HTTPError (400 , reason = "GET takes no request body." )
348
+ raise HTTPError (status_code = 400 , reason = "GET takes no request body." )
349
349
350
350
if self .args .id :
351
351
try :
352
352
smartapi = SmartAPI .get (self .args .id )
353
353
if smartapi .username != self .current_user ["login" ]:
354
- raise HTTPError (403 )
354
+ raise HTTPError (status_code = 403 )
355
355
status = smartapi .check ()
356
356
smartapi .save ()
357
357
except NotFoundError :
358
- raise HTTPError (404 )
358
+ raise HTTPError (status_code = 404 )
359
359
except (ControllerError , AssertionError ) as err :
360
- raise HTTPError (400 , reason = str (err ))
360
+ raise HTTPError (status_code = 400 , reason = str (err ))
361
361
else :
362
362
self .finish ({"success" : True , "details" : status })
363
363
else :
364
- raise HTTPError (400 , reason = "Missing required parameter: id" )
364
+ raise HTTPError (status_code = 400 , reason = "Missing required parameter: id" )
365
365
366
366
@github_authenticated
367
367
def post (self ):
368
368
if self .args .id :
369
369
try :
370
370
smartapi = SmartAPI .get (self .args .id )
371
371
if smartapi .username != self .current_user ["login" ]:
372
- raise HTTPError (403 )
372
+ raise HTTPError (status_code = 403 )
373
373
status = smartapi .check ()
374
374
smartapi .save ()
375
375
except NotFoundError :
376
- raise HTTPError (404 )
376
+ raise HTTPError (status_code = 404 )
377
377
except (ControllerError , AssertionError ) as err :
378
- raise HTTPError (400 , reason = str (err ))
378
+ raise HTTPError (status_code = 400 , reason = str (err ))
379
379
else :
380
380
self .finish ({"success" : True , "details" : status })
381
381
else :
382
- raise HTTPError (400 , reason = "Missing required form field: id" )
382
+ raise HTTPError (status_code = 400 , reason = "Missing required form field: id" )
383
383
384
384
385
385
class MetaKGQueryHandler (QueryHandler ):
0 commit comments