From 469689d0cb32d5e1561b4ae4aa1c7747dab0a2ac Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Fri, 17 May 2024 11:10:57 +0100 Subject: [PATCH] Relax checks on response status code 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 --- bugsnag/delivery.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bugsnag/delivery.py b/bugsnag/delivery.py index acd2da2b..6dc8cd05 100644 --- a/bugsnag/delivery.py +++ b/bugsnag/delivery.py @@ -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) @@ -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) ) @@ -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) )