Skip to content
This repository was archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
removes too many errors exception - just let the cache do its job
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Ponzi committed Feb 28, 2020
1 parent 57754f2 commit 53369b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 0 additions & 4 deletions isitdown/isitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ def check_api_v3(self, url, ip, from_api):
if not self.is_valid_host(host) or is_spam(host) or not self.hostname_exists(host):
return Ping.get_invalid_ping(host)
# 1. We return all the pings to this host in the last 30 seconds.
# 2. if there is a from_ip in the list, return an error.
pings = PingRepository.last_ping_to(host, self.config['BACKOFF_API_CALL_TIME'])
for p in pings:
if p.from_ip == ip:
raise TooManyRequestsException()

# there is a recent ping. Let's use that instead of sending a request.
if len(pings) > 0:
Expand Down
8 changes: 3 additions & 5 deletions isitdown/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ def api_v3(url=""):
:return: a json response object.
"""
ip = request.access_route[-1]
try:
res = isitdown.check_api_v3(url, ip, 3)
return jsonify(isitdown=res.isdown, response_code=res.response_code, host=res.host, deprecated=False)
except TooManyRequestsException:
return jsonify(error="Too many requests to the same URL. Please wait some time."), 429
res = isitdown.check_api_v3(url, ip, 3)
return jsonify(isitdown=res.isdown, response_code=res.response_code, host=res.host, deprecated=False)

# Some static files:
@frontend_bp.route("/favicon.ico")
Expand All @@ -48,6 +45,7 @@ def check(host=""):
return render_template("check.html", last=last_ping_list, pingres=ping)



@frontend_bp.errorhandler(404)
def page_not_found(error):
current_app.logger.error(error)
Expand Down

0 comments on commit 53369b7

Please sign in to comment.