ActiveCampaign/postmark.js

Option to retry failed queries?

Opened this issue · 1 comments

Today I've experienced what might be a short Postmark API outage, which led to some customers not receiving emails.

Would it make sense to add a retry option to the JS client so that these kinds of errors can be worked around?

This is what I've added to my code today, but it might make sense to have this behavior be part of the client:

const sendEmail = async (/* params */)
  let tries = 0;

  while (true) {
    try {
      await postmark.sendEmailWithTemplate(/* params */);
      break;
    } catch (e) {
      if (tries < 5) {
        console.error("Couldn't send email, trying again:", e);
        await new Promise((res) => setTimeout(res, 1000));
        tries++;
      } else {
        throw e;
      }
    }
  }
}

What do you think?

Hi @leolabs

thank you for contacting us regarding adding retries to the library. I will add it to our feature requests list.
Having option to retry does make sense, but I do think that it's better if it's handled on your side.

Handling it externally allows you to take more control of what you can do when the retry needs to happen - like in your example above.

Igor