Skip to content

Commit

Permalink
fix: do not store credential if there was no message to send (#203)
Browse files Browse the repository at this point in the history
* fix: do not store credential if there was no message to send

* chore: throw error instead when there is no message
  • Loading branch information
jeantanzj authored May 6, 2020
1 parent 1c4b661 commit d8622fc
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions backend/src/sms/middlewares/sms.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Campaign, JobQueue } from '@core/models'
import { SmsMessage, SmsTemplate } from '@sms/models'
import { ChannelType } from '@core/constants'
import { TwilioCredentials } from '@sms/interfaces'
import logger from '@core/logger'
import { credentialService } from '@core/services'
import { TwilioService } from '@sms/services'
import config from '@core/config'
Expand Down Expand Up @@ -72,9 +71,8 @@ const getHydratedMsg = async (campaignId: number): Promise<string | null> => {

const sendMessage = async (campaignId: number, recipient: string, credential: TwilioCredentials): Promise<string | void> => {
const msg = await getHydratedMsg(campaignId)
if (!msg) return
if (!msg) throw new Error('No message to send')

logger.info('Sending sms using Twilio.')
const twilioService = new TwilioService(credential)
return twilioService.send(recipient, msg)
}
Expand Down

0 comments on commit d8622fc

Please sign in to comment.