add error handling for changing email in newsletter of user who has not subscribed

This commit is contained in:
Henry Oswald 2018-08-28 10:47:33 +01:00
parent 740571475c
commit 75521a4c86

View file

@ -39,8 +39,11 @@ module.exports =
delete options.body.status
options.body.email_address = newEmail
mailchimp.request options, (err)->
if err? and err?.message?.indexOf("merge fields were invalid")
logger.log {oldEmail, newEmail}, "unable to change email in newsletter as user has not subscribed"
return callback()
# if the user has unsubscribed mailchimp will error on email address change
if err? and err?.message.indexOf("could not be validated") == -1
else if err? and err?.message?.indexOf("could not be validated") == -1
logger.err err:err, "error changing email in newsletter"
return callback(err)
else