diff --git a/bugsnag/delivery.py b/bugsnag/delivery.py index acd2da2..6dc8cd0 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) )