Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Support Consul response code: 429
Browse files Browse the repository at this point in the history
Consul returns a 429 response code when: Some healthchecks are passing, at
least one is warning (see https://www.consul.io/api-docs/agent/service).

This PR updates the callback handler to support response code 429.
  • Loading branch information
kkzo authored and Kiran Naidoo committed Dec 31, 2020
1 parent b105755 commit e5d4af8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion consul/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class ClientError(ConsulException):
"""Encapsulates 4xx Http error code"""
pass

class ConsulUnhealthy(ConsulException):
"""
429 response code: Some healthchecks are passing, at least one is warning
"""
pass

#
# Convenience to define checks
Expand Down Expand Up @@ -194,7 +199,7 @@ def _compat(

class CB(object):
@classmethod
def _status(klass, response, allow_404=True):
def _status(klass, response, allow_404=True, allow_429=True):
# status checking
if 400 <= response.code < 500:
if response.code == 400:
Expand All @@ -206,6 +211,9 @@ def _status(klass, response, allow_404=True):
elif response.code == 404:
if not allow_404:
raise NotFound(response.body)
elif response.code == 429:
if not allow_429:
raise ConsulUnhealthy(response.body)
else:
raise ClientError("%d %s" % (response.code, response.body))
elif 500 <= response.code < 600:
Expand Down

0 comments on commit e5d4af8

Please sign in to comment.