Skip to content

Commit

Permalink
Merge pull request #606 from legumeinfo/linkouts-603
Browse files Browse the repository at this point in the history
improved error handling for #603
  • Loading branch information
adf-ncgr authored Sep 11, 2023
2 parents 337835e + ed1d776 commit d11cd02
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions linkouts/linkouts/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

async def http_genes_get_handler(request):
# parse the query from the request query string
ids = request.rel_url.query[GENES_QUERY]
try:
ids = request.rel_url.query[GENES_QUERY]
except KeyError:
raise web.HTTPBadRequest(text="No " + GENES_QUERY + " supplied")
ids = ids.split(",")
handler = request.app["handler"]
linkouts = handler.process_genes(ids)
Expand All @@ -21,14 +24,22 @@ async def http_genes_post_handler(request):
# parse the query from the request POST data
data = await request.json()
ids = data.get(GENES_QUERY, [])
if type(ids) != list:
raise web.HTTPBadRequest(text=GENES_QUERY + " must be given as list")
if len(ids) == 0:
raise web.HTTPBadRequest(text="No " + GENES_QUERY + " supplied")

handler = request.app["handler"]
linkouts = handler.process_genes(ids)
return web.json_response(linkouts)


async def http_genomic_regions_get_handler(request):
# parse the query from the request query string
ids = request.rel_url.query[GENOMIC_REGIONS_QUERY]
try:
ids = request.rel_url.query[GENOMIC_REGIONS_QUERY]
except KeyError:
raise web.HTTPBadRequest(text="No " + GENOMIC_REGIONS_QUERY + " supplied")
ids = ids.split(",")
handler = request.app["handler"]
linkouts = handler.process_genomic_regions(ids)
Expand All @@ -39,6 +50,11 @@ async def http_genomic_regions_post_handler(request):
# parse the query from the request POST data
data = await request.json()
ids = data.get(GENOMIC_REGIONS_QUERY, [])
if type(ids) != list:
raise web.HTTPBadRequest(text=GENOMIC_REGIONS_QUERY + " must be given as list")
if len(ids) == 0:
raise web.HTTPBadRequest(text="No " + GENOMIC_REGIONS_QUERY + " supplied")

handler = request.app["handler"]
linkouts = handler.process_genomic_regions(ids)
return web.json_response(linkouts)
Expand Down

0 comments on commit d11cd02

Please sign in to comment.