Permalink
Browse files

fix(sms): make the fallback error case work sanely

#1663

r=vbudhram
  • Loading branch information...
1 parent 7226ce0 commit 3eff2d306e9c613b4f0293844fde26f37dc555e9 @philbooth philbooth committed on GitHub Feb 16, 2017
Showing with 44 additions and 7 deletions.
  1. +9 −7 lib/routes/sms.js
  2. +35 −0 test/local/routes/sms.js
View
@@ -76,15 +76,17 @@ module.exports = (log, isA, error, config, customs, sms) => {
function sendMessage (senderId) {
return sms.send(phoneNumber, senderId, messageId, acceptLanguage)
.catch(err => {
- if (err.status === 500) {
- throw error.messageRejected(err.reason, err.reasonCode)
+ if (err) {
+ if (err.status === 500) {
+ throw error.messageRejected(err.reason, err.reasonCode)
+ }
+
+ if (err.status === 400) {
+ throw error.invalidMessageId()
+ }
}
- if (err.status === 400) {
- throw error.invalidMessageId()
- }
-
- throw new error.unexpectedError()
+ throw error.unexpectedError()
})
}
@@ -303,6 +303,41 @@ describe('/sms', () => {
assert.equal(err.message, 'Invalid message id')
})
})
+
+ describe('sms.send fails with unknown error', () => {
+ let err
+
+ beforeEach(() => {
+ sms.send = sinon.spy(() => P.reject())
+ request.payload.phoneNumber = '+18885083401'
+ return runTest(route, request)
+ .catch(e => {
+ err = e
+ })
+ })
+
+ it('called log.begin once', () => {
+ assert.equal(log.begin.callCount, 1)
+ })
+
+ it('called request.validateMetricsContext once', () => {
+ assert.equal(request.validateMetricsContext.callCount, 1)
+ })
+
+ it('called sms.send once', () => {
+ assert.equal(sms.send.callCount, 1)
+ })
+
+ it('did not call log.flowEvent', () => {
+ assert.equal(log.flowEvent.callCount, 0)
+ })
+
+ it('threw the correct error data', () => {
+ assert.ok(err instanceof AppError)
+ assert.equal(err.errno, AppError.ERRNO.UNEXPECTED_ERROR)
+ assert.equal(err.message, 'Unspecified error')
+ })
+ })
})
describe('/sms disabled', () => {

0 comments on commit 3eff2d3

Please sign in to comment.