Skip to content

Commit

Permalink
Relax checks on response status code
Browse files Browse the repository at this point in the history
Currently we require a 200 status code for events and a 202 for sessions
but there's no need to be so specific as any 2xx status indicates
success

Now we only warn on codes outside of the 2xx range, unless a specific
code has been set in `options['success']`. If a specific code is given
then it must match exactly, i.e. it has the same behaviour as before
  • Loading branch information
imjoehaines committed May 21, 2024
1 parent a3ee85e commit 469689d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bugsnag/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def deliver_sessions(self, config, payload: Any, options=None):
options = {}

options['endpoint'] = config.session_endpoint
options['success'] = 202

self.deliver(config, payload, options)

Expand Down Expand Up @@ -151,10 +150,14 @@ def request():
status = resp.getcode()

if 'success' in options:
success = options['success']
# if an expected status code has been given then it must match
# exactly with the actual status code
success = status == options['success']
else:
success = 200
if status != success:
# warn if we don't get a 2xx status code by default
success = status >= 200 and status < 300

if not success:
config.logger.warning(
'Delivery to %s failed, status %d' % (uri, status)
)
Expand Down Expand Up @@ -184,12 +187,16 @@ def request():

response = requests.post(uri, **req_options)
status = response.status_code

if 'success' in options:
success = options['success']
# if an expected status code has been given then it must match
# exactly with the actual status code
success = status == options['success']
else:
success = requests.codes.ok
# warn if we don't get a 2xx status code by default
success = status >= 200 and status < 300

if status != success:
if not success:
config.logger.warning(
'Delivery to %s failed, status %d' % (uri, status)
)
Expand Down

0 comments on commit 469689d

Please sign in to comment.