1717from controller .exceptions import ControllerError , NotFoundError
1818from pipeline import MetaKGQueryPipeline
1919from utils .downloader import DownloadError , download_async
20+ from utils .http_error import SmartAPIHTTPError
2021from utils .metakg .biolink_helpers import get_expanded_values
2122from utils .metakg .cytoscape_formatter import CytoscapeDataFormatter
2223from utils .metakg .export import edges2graphml
@@ -68,7 +69,7 @@ def get(self):
6869 # raising HTTPError will cause headers to be emptied
6970 self .finish ()
7071 else :
71- raise HTTPError (403 )
72+ raise HTTPError (status_code = 403 )
7273
7374
7475class LoginHandler (AuthHandler ):
@@ -113,7 +114,7 @@ class ValidateHandler(BaseHandler):
113114
114115 async def get (self ):
115116 if self .request .body :
116- raise HTTPError (400 , reason = "GET takes no request body." )
117+ raise HTTPError (status_code = 400 , reason = "GET takes no request body." )
117118
118119 raw = await self .download (self .args .url )
119120 self .validate (raw )
@@ -139,9 +140,8 @@ def validate(self, raw):
139140 smartapi = SmartAPI (SmartAPI .VALIDATION_ONLY )
140141 smartapi .raw = raw
141142 smartapi .validate ()
142-
143143 except (ControllerError , AssertionError ) as err :
144- raise HTTPError (400 , reason = str (err ))
144+ raise SmartAPIHTTPError (400 , reason = str (err ))
145145 else :
146146 self .finish ({"success" : True , "details" : f"valid SmartAPI ({ smartapi .version } ) metadata." })
147147
@@ -165,19 +165,19 @@ async def post(self):
165165 """
166166
167167 if SmartAPI .find (self .args .url , "url" ):
168- raise HTTPError (409 )
168+ raise HTTPError (status_code = 409 )
169169
170170 try :
171171 file = await download_async (self .args .url )
172172 except DownloadError as err :
173- raise HTTPError (400 , reason = str (err )) from err
173+ raise HTTPError (status_code = 400 , reason = str (err )) from err
174174
175175 try :
176176 smartapi = SmartAPI (self .args .url )
177177 smartapi .raw = file .raw
178178 smartapi .validate ()
179179 except (ControllerError , AssertionError ) as err :
180- raise HTTPError (400 , reason = str (err )) from err
180+ raise HTTPError (status_code = 400 , reason = str (err )) from err
181181
182182 if self .args .dryrun :
183183 raise Finish ({"success" : True , "details" : f"[Dryrun] Valid { smartapi .version } Metadata" })
@@ -187,7 +187,7 @@ async def post(self):
187187 smartapi .refresh (file ) # populate webdoc meta
188188 _id = smartapi .save ()
189189 except ControllerError as err :
190- raise HTTPError (400 , reason = str (err )) from err
190+ raise HTTPError (status_code = 400 , reason = str (err )) from err
191191 else :
192192 self .finish ({"success" : True , "_id" : _id })
193193 await self ._notify (smartapi )
@@ -252,21 +252,21 @@ async def put(self, _id):
252252 try :
253253 smartapi = SmartAPI .get (_id )
254254 except NotFoundError :
255- raise HTTPError (404 )
255+ raise HTTPError (status_code = 404 )
256256
257257 if smartapi .username != self .current_user ["login" ]:
258- raise HTTPError (403 )
258+ raise HTTPError (status_code = 403 )
259259
260260 if self .args .slug is not None :
261261 if self .args .slug in {"api" }: # reserved
262- raise HTTPError (400 , reason = "slug is reserved" )
262+ raise HTTPError (status_code = 400 , reason = "slug is reserved" )
263263
264264 try : # update slug
265265 smartapi .slug = self .args .slug or None
266266 smartapi .save ()
267267
268268 except (ControllerError , ValueError ) as err :
269- raise HTTPError (400 , reason = str (err )) from err
269+ raise HTTPError (status_code = 400 , reason = str (err )) from err
270270
271271 self .finish ({"success" : True })
272272
@@ -292,15 +292,15 @@ def delete(self, _id):
292292 try :
293293 smartapi = SmartAPI .get (_id )
294294 except NotFoundError :
295- raise HTTPError (404 )
295+ raise HTTPError (status_code = 404 )
296296
297297 if smartapi .username != self .current_user ["login" ]:
298- raise HTTPError (403 )
298+ raise HTTPError (status_code = 403 )
299299
300300 try :
301301 _id = smartapi .delete ()
302302 except ControllerError as err :
303- raise HTTPError (400 , reason = str (err )) from err
303+ raise HTTPError (status_code = 400 , reason = str (err )) from err
304304
305305 self .finish ({"success" : True , "_id" : _id })
306306
@@ -346,41 +346,41 @@ class UptimeHandler(BaseHandler):
346346 @github_authenticated
347347 def get (self ):
348348 if self .request .body :
349- raise HTTPError (400 , reason = "GET takes no request body." )
349+ raise HTTPError (status_code = 400 , reason = "GET takes no request body." )
350350
351351 if self .args .id :
352352 try :
353353 smartapi = SmartAPI .get (self .args .id )
354354 if smartapi .username != self .current_user ["login" ]:
355- raise HTTPError (403 )
355+ raise HTTPError (status_code = 403 )
356356 status = smartapi .check ()
357357 smartapi .save ()
358358 except NotFoundError :
359- raise HTTPError (404 )
359+ raise HTTPError (status_code = 404 )
360360 except (ControllerError , AssertionError ) as err :
361- raise HTTPError (400 , reason = str (err ))
361+ raise HTTPError (status_code = 400 , reason = str (err ))
362362 else :
363363 self .finish ({"success" : True , "details" : status })
364364 else :
365- raise HTTPError (400 , reason = "Missing required parameter: id" )
365+ raise HTTPError (status_code = 400 , reason = "Missing required parameter: id" )
366366
367367 @github_authenticated
368368 def post (self ):
369369 if self .args .id :
370370 try :
371371 smartapi = SmartAPI .get (self .args .id )
372372 if smartapi .username != self .current_user ["login" ]:
373- raise HTTPError (403 )
373+ raise HTTPError (status_code = 403 )
374374 status = smartapi .check ()
375375 smartapi .save ()
376376 except NotFoundError :
377- raise HTTPError (404 )
377+ raise HTTPError (status_code = 404 )
378378 except (ControllerError , AssertionError ) as err :
379- raise HTTPError (400 , reason = str (err ))
379+ raise HTTPError (status_code = 400 , reason = str (err ))
380380 else :
381381 self .finish ({"success" : True , "details" : status })
382382 else :
383- raise HTTPError (400 , reason = "Missing required form field: id" )
383+ raise HTTPError (status_code = 400 , reason = "Missing required form field: id" )
384384
385385
386386class MetaKGHandlerMixin :
@@ -600,14 +600,14 @@ def write(self, chunk):
600600
601601class MetaKGPathFinderHandler (QueryHandler ):
602602 """
603- A handler for querying paths in a knowledge graph using MetaKGPathFinder.
603+ A handler for querying paths in a knowledge graph using the custom MetaKGPathFinder module .
604604
605605 Attributes:
606606 - name: Unique identifier for this handler.
607607 - kwargs: Configuration for GET request parameters.
608608
609- The primary GET method accepts 'subject', 'object', and 'cutoff' parameters, then retrieves
610- and returns paths in JSON format between the specified entities up to the given 'cutoff' length.
609+ The primary GET method accepts the required 'subject', 'object', and 'cutoff'(default=3) parameters, then retrieves
610+ and returns paths in JSON format between the specified nodes up to the given 'cutoff' length.
611611 """
612612
613613 name = "metakgpathfinder"
@@ -672,6 +672,11 @@ def setup_pathfinder_rawquery(self, expanded_fields):
672672
673673 @capture_exceptions
674674 async def get (self , * args , ** kwargs ):
675+
676+ # Check if subject and object are the same - not allowed
677+ if self .args .subject == self .args .object :
678+ raise ValueError ("Subject and object must be different." )
679+
675680 query_data = {"q" : self .args .q }
676681
677682 # Initialize with the original subject and object, and setup for expansion
@@ -715,6 +720,10 @@ async def get(self, *args, **kwargs):
715720 bte = self .args .bte
716721 )
717722
723+ # # Error check path results
724+ if "error" in paths_with_edges :
725+ raise HTTPError (400 , reason = str (paths_with_edges ["error" ]))
726+
718727 # Check if rawquery parameter is true -- respond with correct output
719728 if self .args .rawquery :
720729 raw_query_output = self .setup_pathfinder_rawquery (expanded_fields )
0 commit comments