Skip to content

Commit

Permalink
fixing response type boolean when user not authorized
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Jun 10, 2024
1 parent 999dda7 commit 8f3e87c
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions beacon/request/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,19 @@ async def wrapper(request: Request):
try:
response_type = response_type_dict[username]
except Exception:
#LOG.debug(Exception)
response_type = ['boolean']
if response_type is not None:
for response_typed in response_type:
#LOG.debug(response_typed)
if response_typed == 'boolean':
qparams.query.requested_granularity = Granularity.BOOLEAN
elif response_typed == 'count':
qparams.query.requested_granularity = Granularity.COUNT
elif response_typed == 'record':
qparams.query.requested_granularity = Granularity.RECORD
pass
try:
if response_type is not None:
for response_typed in response_type:
#LOG.debug(response_typed)
if response_typed == 'boolean':
qparams.query.requested_granularity = Granularity.BOOLEAN
elif response_typed == 'count':
qparams.query.requested_granularity = Granularity.COUNT
elif response_typed == 'record':
qparams.query.requested_granularity = Granularity.RECORD
except Exception:
pass


entry_id = request.match_info.get('id', None)
Expand Down Expand Up @@ -214,19 +216,20 @@ async def wrapper(request: Request):
except Exception as err:
qparams = ''
if str(err) == 'Not Found':
error = build_beacon_error_response(404, qparams, str('error'))
error = build_beacon_error_response(404, qparams, str(err))
raise web.HTTPNotFound(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Bad Request':
error = build_beacon_error_response(400, qparams, str('error'))
error = build_beacon_error_response(400, qparams, str(err))
raise web.HTTPBadRequest(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Bad Gateway':
error = build_beacon_error_response(502, qparams, str('error'))
error = build_beacon_error_response(502, qparams, str(err))
raise web.HTTPBadGateway(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Method Not Allowed':
error = build_beacon_error_response(405, qparams, str('error'))
error = build_beacon_error_response(405, qparams, str(err))
raise web.HTTPMethodNotAllowed(text=json.dumps(error), content_type='application/json')
else:
error = build_beacon_error_response(500, qparams, str('error'))
LOG.debug(err)
error = build_beacon_error_response(500, qparams, str(err))
raise web.HTTPInternalServerError(text=json.dumps(error), content_type='application/json')

return await json_stream(request, response)
Expand Down Expand Up @@ -327,19 +330,20 @@ async def wrapper(request: Request):
except Exception as err:
qparams = ''
if str(err) == 'Not Found':
error = build_beacon_error_response(404, qparams, str('error'))
error = build_beacon_error_response(404, qparams, str(err))
raise web.HTTPNotFound(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Bad Request':
error = build_beacon_error_response(400, qparams, str('error'))
error = build_beacon_error_response(400, qparams, str(err))
raise web.HTTPBadRequest(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Bad Gateway':
error = build_beacon_error_response(502, qparams, str('error'))
error = build_beacon_error_response(502, qparams, str(err))
raise web.HTTPBadGateway(text=json.dumps(error), content_type='application/json')
elif str(err) == 'Method Not Allowed':
error = build_beacon_error_response(405, qparams, str('error'))
error = build_beacon_error_response(405, qparams, str(err))
raise web.HTTPMethodNotAllowed(text=json.dumps(error), content_type='application/json')
else:
error = build_beacon_error_response(500, qparams, str('error'))
LOG.debug(err)
error = build_beacon_error_response(500, qparams, str(err))
raise web.HTTPInternalServerError(text=json.dumps(error), content_type='application/json')

return await json_stream(request, response)
Expand Down

0 comments on commit 8f3e87c

Please sign in to comment.