Skip to content

Option to retry failed queries? #129

@leolabs

Description

@leolabs

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions