fix(push): do not throw if push fails on the notify endpoint

Fixes #1510
This commit is contained in:
vladikoff 2016-10-28 20:11:54 -04:00
Родитель 04d9fc5ecb
Коммит 90b37d5ab5
3 изменённых файлов: 42 добавлений и 2 удалений

Просмотреть файл

@ -113,7 +113,7 @@ function main() {
function (err) {
if (err) {
log.error({ op: 'server.start.1', msg: 'failed startup with error',
err: { message: err.message } })
err: { message: err.message } })
process.exit(1)
} else {
log.info({ op: 'server.start.1', msg: 'running on ' + server.info.uri })

Просмотреть файл

@ -1201,12 +1201,25 @@ module.exports = function (
var endpointAction = 'devicesNotify'
var stringUid = uid.toString('hex')
function catchPushError(err) {
// push may fail due to not found devices or a bad push action
// log the error but still respond with a 200.
log.error({
op: 'Account.devicesNotify',
uid: stringUid,
error: err
})
}
return customs.checkAuthenticated(endpointAction, ip, stringUid)
.then(function () {
if (body.to === 'all') {
return push.pushToAllDevices(uid, endpointAction, pushOptions)
.catch(catchPushError)
} else {
return push.pushToDevices(uid, body.to, endpointAction, pushOptions)
.catch(catchPushError)
}
})
.done(

Просмотреть файл

@ -466,7 +466,7 @@ test('/account/device', function (t) {
})
test('/account/devices/notify', function (t) {
t.plan(5)
t.plan(6)
var config = {}
var uid = uuid.v4('binary')
var mockRequest = mocks.mockRequest({
@ -599,6 +599,33 @@ test('/account/devices/notify', function (t) {
t.equal(err.message, 'Client has sent too many requests')
})
})
t.test('logs error if no devices found', function (t) {
t.plan(1)
mockRequest.payload = {
to: ['bogusid1', 'bogusid2'],
TTL: 60,
payload: pushPayload
}
var mockLog = mocks.spyLog()
var mockPush = mocks.mockPush({
pushToDevices: () => P.reject('Devices ids not found in devices')
})
var mockCustoms = {
checkAuthenticated: () => P.resolve()
}
route = getRoute(makeRoutes({
customs: mockCustoms,
log: mockLog,
push: mockPush
}), '/account/devices/notify')
return runTest(route, mockRequest, function (response) {
t.equal(JSON.stringify(response), '{}', 'response should not throw push errors')
})
})
})
test('/account/device/destroy', function (t) {