From 8aa510d7c30d4d2748cf3d2d9330e8d3ffb85a78 Mon Sep 17 00:00:00 2001 From: jrconlin Date: Thu, 30 Mar 2017 14:44:40 -0700 Subject: [PATCH] bug: Use log.error() to better track exceptions in APNS fixes: #855 --- autopush/router/apnsrouter.py | 9 +++++++-- autopush/tests/test_router.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/autopush/router/apnsrouter.py b/autopush/router/apnsrouter.py index 3cd6da6e..3ebf4b42 100644 --- a/autopush/router/apnsrouter.py +++ b/autopush/router/apnsrouter.py @@ -4,6 +4,7 @@ from hyper.http20.exceptions import ConnectionError, HTTP20Error from twisted.internet.threads import deferToThread from twisted.logger import Logger +from twisted.python.failure import Failure from autopush.exceptions import RouterException from autopush.router.apns2 import ( @@ -146,18 +147,22 @@ def _route(self, notification, router_data): try: apns_client.send(router_token=router_token, payload=payload, apns_id=apns_id) - except ConnectionError: + except ConnectionError as ex: self.ap_settings.metrics.increment( "updates.client.bridge.apns.connection_err", self._base_tags ) + self.log.error("Connection Error sending to APNS", + log_failure=Failure(ex)) raise RouterException( "Server error", status_code=502, response_body="APNS returned an error processing request", log_exception=False, ) - except HTTP20Error: + except HTTP20Error as ex: + self.log.error("HTTP2 Error sending to APNS", + log_failure=Failure(ex)) raise RouterException( "Server error", status_code=502, diff --git a/autopush/tests/test_router.py b/autopush/tests/test_router.py index 74f08e87..a6253b3a 100644 --- a/autopush/tests/test_router.py +++ b/autopush/tests/test_router.py @@ -161,6 +161,7 @@ def raiser(*args, **kwargs): eq_(e.exception.response_body, 'APNS returned an error ' 'processing request') eq_(e.exception.status_code, 502) + self.flushLoggedErrors() @inlineCallbacks def test_route_notification(self): @@ -230,6 +231,7 @@ def throw(*args, **kwargs): eq_(ex.exception.message, "Server error") eq_(ex.exception.response_body, 'APNS returned an error processing ' 'request') + self.flushLoggedErrors() def test_too_many_connections(self): rr = self.router.apns['firefox']