Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: improve handling of JSONResponseErrors
Browse files Browse the repository at this point in the history
have websocket log them instead of passing along to sentry and give them
a metric

closes #703
  • Loading branch information
pjenvey committed Oct 20, 2016
1 parent 97a453a commit 8cbe294
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 6 additions & 3 deletions autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ def wrapper(self, *args, **kwargs):
except ProvisionedThroughputExceededException:
self.metrics.increment("error.provisioned.%s" % func.__name__)
raise
except JSONResponseError:
self.metrics.increment("error.jsonresponse.%s" % func.__name__)
raise
except BotoServerError:
self.metrics.increment("error.botoserver.%s" % func.__name__)
raise
Expand Down Expand Up @@ -535,9 +538,9 @@ def fetch_messages(self, uaid, limit=10):
"""
# Eagerly fetches all results in the result set.
results = list(self.table.query_2(uaid__eq=hasher(uaid.hex),
chidmessageid__gt=" ",
consistent=True, limit=limit))
results = self.table.query_2(uaid__eq=hasher(uaid.hex),
chidmessageid__gt=" ",
consistent=True, limit=limit)
return [
WebPushNotification.from_message_table(uaid, x) for x in results
]
Expand Down
7 changes: 7 additions & 0 deletions autopush/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import twisted.internet.base
from autopush.tests.test_db import make_webpush_notification
from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException
from boto.exception import JSONResponseError
from cyclone.web import Application
from mock import Mock, patch
from nose.tools import assert_raises, eq_, ok_
from txstatsd.metrics.metrics import Metrics
from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.internet.error import ConnectError
from twisted.python.failure import Failure
from twisted.trial import unittest

import autopush.db as db
Expand Down Expand Up @@ -2113,6 +2115,11 @@ def test_incomplete_uaid(self):
ok_(fr.called)
eq_(fr.call_args[0], (mm.drop_user, uaid))

def test_log_failure_jsonresponseerror(self):
self.proto.log_failure(Failure(JSONResponseError(None, None)))
self.proto.log.info.assert_called()
self.proto.log.failure.assert_not_called()


class RouterHandlerTestCase(unittest.TestCase):
def setUp(self):
Expand Down
7 changes: 6 additions & 1 deletion autopush/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
ProvisionedThroughputExceededException,
ItemNotFound
)
from boto.exception import JSONResponseError
from twisted.internet import reactor
from twisted.internet.defer import (
Deferred,
Expand Down Expand Up @@ -317,7 +318,11 @@ def base_tags(self):

def log_failure(self, failure, **kwargs):
"""Log a twisted failure out through twisted's log.failure"""
self.log.failure(format="Unexpected error", failure=failure, **kwargs)
exc = failure.value
if isinstance(exc, JSONResponseError):
self.log.info("JSONResponseError: {exc}", exc=exc, **kwargs)
else:
self.log.failure(format="Unexpected error", failure=failure, **kwargs)

@property
def paused(self):
Expand Down

0 comments on commit 8cbe294

Please sign in to comment.