Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to retry failed queries? #129

Open
leolabs opened this issue Jun 14, 2023 · 1 comment
Open

Option to retry failed queries? #129

leolabs opened this issue Jun 14, 2023 · 1 comment
Assignees

Comments

@leolabs
Copy link

leolabs commented Jun 14, 2023

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?

@ibalosh
Copy link
Contributor

ibalosh commented Jun 27, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants