function addSubscriber(firstName, lastName, email) {
  return mailchimp
    .post(SUBSCRIBER_LIST_API_PATH, {
      email_address: email,
      status: 'subscribed',
      merge_fields: {
        FNAME: firstName,
        LNAME: lastName
      }
    })
    .then(() => {
      // Ignore result, it was successful. Do not pass result to caller (abstraction)
      return Promise.resolve();
    })
    .catch(err => {
      if (err.status === 400 && err.title === 'Member Exists') {
        // Catch `already subscribed` error and ignore
        console.log(`${email} is already a member of list ${SUBSCRIBER_LIST_ID}`);
        return Promise.resolve();
      }

      // Encapsulate error for caller
      return Promise.reject(new SubscribeUserError(err));
    });
}
/**
 * Adds an email to the preset subscriber list.
 *
 * @param firstName user's first name
 * @param lastName user's last name
 * @param email the email to add to the list (user's email)
 * @returns a promise
 */
Adds an email to the preset subscriber list.
@param firstName user's first name
@param lastName user's last name
@param email the email to add to the list (user's email)
@returns a promise
Adds an email to the preset subscriber list . @param firstName user ' s first name @param lastName user ' s last name @param email the email to add to the list ( user ' s email ) @returns a promise
function addSubscriber(firstName, lastName, email) {
  return mailchimp
    .post(SUBSCRIBER_LIST_API_PATH, {
      email_address: email,
      status: 'subscribed',
      merge_fields: {
        FNAME: firstName,
        LNAME: lastName
      }
    })
    .then(() => {
      return Promise.resolve();
    })
    .catch(err => {
      if (err.status === 400 && err.title === 'Member Exists') {
        console.log(`${email} is already a member of list ${SUBSCRIBER_LIST_ID}`);
        return Promise.resolve();
      }
      return Promise.reject(new SubscribeUserError(err));
    });
}
function addSubscriber ( firstName , lastName , email ) { return mailchimp . post ( SUBSCRIBER_LIST_API_PATH , { email_address : email , status : 'subscribed' , merge_fields : { FNAME : firstName , LNAME : lastName } } ) . then ( ( ) => { return Promise . resolve ( ) ; } ) . catch ( err => { if ( err . status === 400 && err . title === 'Member Exists' ) { console . log ( ` ${ email } ${ SUBSCRIBER_LIST_ID } ` ) ; return Promise . resolve ( ) ; } return Promise . reject ( new SubscribeUserError ( err ) ) ; } ) ; }
Adds an email to the preset subscriber list.
Adds an email to the preset subscriber list .
// Ignore result, it was successful. Do not pass result to caller (abstraction) // Catch `already subscribed` error and ignore // Encapsulate error for caller