Browse Source

count-based error modified to be included in error 400, 404, 500

master
Your Name 4 years ago
parent
commit
8a9e57cbf5
  1. 47
      api.py

47
api.py

@ -189,9 +189,7 @@ def api_args():
api_phrase.append(random.choice(toChooseFrom[testKey]))
api_phrase[0] = api_phrase[0].capitalize()
api_phrase_str_word = ' '.join(api_phrase)
print('api_phrase_str_word: ',api_phrase_str_word)
api_phrase_str = api_phrase_str + '\\n' + api_phrase_str_word
print('api_phrase_str: ',api_phrase_str)
api_phrase_str_word = ''
api_phrase_str = api_phrase_str[2:]
@ -239,9 +237,19 @@ def api_args():
refusal_message = build_error_two()
org = 'someone'
request_type = 'unknown request'
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
out = counter.value
if out < 10:
with counter.get_lock():
counter.value += 1
out = counter.value
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
else:
with counter.get_lock():
counter.value = 0
refusal_code = 402
refusal_message = build_error_three()
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
@ -253,9 +261,18 @@ def error_fourzerozero(e):
refusal_message = build_error_two()
org = 'someone'
request_type = 'unknown request'
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
out = counter.value
if out < 10:
with counter.get_lock():
counter.value += 1
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
else:
with counter.get_lock():
counter.value = 0
refusal_code = 402
refusal_message = build_error_three()
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
@app.errorhandler(404)
@ -266,9 +283,18 @@ def error_fourzerofour(e):
refusal_message = build_error_two()
org = 'someone'
request_type = 'unknown request'
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
out = counter.value
if out < 10:
with counter.get_lock():
counter.value += 1
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
else:
with counter.get_lock():
counter.value = 0
refusal_code = 402
refusal_message = build_error_three()
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
@app.errorhandler(500)
@ -279,9 +305,18 @@ def error_fivezerozero(e):
refusal_message = build_error_two()
org = 'someone'
request_type = 'unknown request'
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message )
out = counter.value
if out < 10:
with counter.get_lock():
counter.value += 1
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
else:
with counter.get_lock():
counter.value = 0
refusal_code = 402
refusal_message = build_error_three()
add_error_db(timestamp,org,seedText,request_type,refusal_code,refusal_message)
return jsonify(refusal_message)
# app.run()

Loading…
Cancel
Save