0

My task is to count the number of times a client in a network requests for service and send the response only on the 5th request. My application is in Flask and my code looks like:

count = 0
@test.route('/testurl/<par>', methods=["GET"])
def fun(par):
    if request.method == 'GET':
        global count
        count += 1
        if count == 5:
            return jsonify({"data": "something"})

Clearly, if the count is not equal to 5, the function won't send any response and flask will raise an error. I just want to suppress the error and not show it in the terminal because my code is working fine. I'm not sure how to use try-except in this and don't know about any decorator which can do this. Can somebody help?

gcoderx
  • 53
  • 1
  • 6

0 Answers0