Skip to content

Commit

Permalink
update error handling in v2/autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar4l committed Mar 18, 2024
1 parent 8f2ea2a commit 1b13086
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions code4me-server/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def autocomplete_v2():
# TODO: As we want every request to be authorised, this can be extracted into a decorator
user_uuid = authorise(request)
request_json = request.json
# current_app.logger.warning(request_json)

# TODO: add a None filter type for baseline comparison
filter_time, filter_type, should_filter = filter_request(user_uuid, request_json)

predict_time, predictions = get_predictions(request_json) \
Expand Down Expand Up @@ -90,11 +90,15 @@ def autocomplete_v2():
}

except Exception as e:
# logging may be a good idea for debugging

error_uuid = uuid.uuid4().hex
current_app.logger.warning(f'''
Error {error_uuid} for {user_uuid if user_uuid is not None else "unauthenticated user"}
{request.json if request.is_json else "no request json found"}
''')
traceback.print_exc()
return response({
"error": str(e)
}, status=400)

return response({ "error": error_uuid }, status=400)

@v2.route("/prediction/verify", methods=["POST"])
@limiter.limit("4000/hour")
Expand Down

0 comments on commit 1b13086

Please sign in to comment.