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

Commit

Permalink
fix: do not return error informtion for 500 errors for router
Browse files Browse the repository at this point in the history
closes #698
  • Loading branch information
jrconlin committed Oct 13, 2016
1 parent 6e20a95 commit 5206cab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions autopush/router/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ def _route(self, notification, router_data):
time_to_live=router_ttl,
)
except pyfcm.errors.AuthenticationError as e:
raise self._error("Authentication Error: %s" % e, 500)
self.log.error("Authentication Error: %s" % e)
raise RouterException("Server error", status_code=500)
except Exception as e:
raise self._error("Unhandled exception in FCM Routing: %s" % e,
500)
self.log.error("Unhandled FCM Error: %s" % e)
raise RouterException("Server error", status_code=500)
self.metrics.increment("updates.client.bridge.fcm.attempted",
self._base_tags)
return self._process_reply(result, notification, router_data,
Expand Down
12 changes: 7 additions & 5 deletions autopush/router/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ def _route(self, notification, uaid_data):
gcm = self.gcm[creds['senderID']]
result = gcm.send(payload)
except KeyError:
raise self._error("Server error, missing bridge credentials " +
"for %s" % creds.get("senderID"), 500)
self.log.critical("Missing GCM bridge credentials for : %s" %
creds.get("senderID"))
raise RouterException("Server error", status_code=500)
except gcmclient.GCMAuthenticationError as e:
raise self._error("Authentication Error: %s" % e, 500)
self.log.error("GCM Authentication Error: %s" % e)
raise RouterException("Server error", status_code=500)
except Exception as e:
raise self._error("Unhandled exception in GCM Routing: %s" % e,
500)
self.log.error("Unhandled exception in GCM Routing: %s" % e)
raise RouterException("Server error", status_code=500)
self.metrics.increment("updates.client.bridge.gcm.attempted",
self._base_tags)
return self._process_reply(result, uaid_data, ttl=router_ttl,
Expand Down
10 changes: 6 additions & 4 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ def setUp(self, fgcm):
self.mock_result = mock_result
fgcm.send.return_value = mock_result

def _check_error_call(self, exc, code):
def _check_error_call(self, exc, code, response=None):
ok_(isinstance(exc, RouterException))
eq_(exc.status_code, code)
ok_(self.router.gcm['test123'].send.called)
if response:
eq_(exc.response_body, response)
self.flushLoggedErrors()

def test_init(self):
Expand Down Expand Up @@ -449,7 +451,7 @@ def throw_auth(arg):
d = self.router.route_notification(self.notif, self.router_data)

def check_results(fail):
self._check_error_call(fail.value, 500)
self._check_error_call(fail.value, 500, "Server error")
d.addBoth(check_results)
return d

Expand All @@ -461,7 +463,7 @@ def throw_other(arg):
d = self.router.route_notification(self.notif, self.router_data)

def check_results(fail):
self._check_error_call(fail.value, 500)
self._check_error_call(fail.value, 500, "Server error")
d.addBoth(check_results)
return d

Expand Down Expand Up @@ -514,7 +516,7 @@ def test_router_notification_gcm_no_auth(self):
{"router_data": {"token": "abc"}})

def check_results(fail):
eq_(fail.value.status_code, 500)
eq_(fail.value.status_code, 500, "Server error")
d.addBoth(check_results)
return d

Expand Down

0 comments on commit 5206cab

Please sign in to comment.