0

我正在使用exponential-backoffnpm 模块(尽管我认为这也适用于更广泛使用的backoff模块)。我不确定什么样的失败会触发“重试”。

我有一个非常简单的 fetch 方法被调用:

async function register() {
  ...
  const response = await backOff(() => fetch(apiUrl, {
    method: 'POST',
    body: JSON.stringify(someBodyParams),
  }),
  {
    retry: (e, attemptNumber) => console.log({ event: e, attemptNumber }),
  });

  if (!response.ok) {
    const text = await response.text();
    const errorMessage = `Problem with fetch: ${text}`;
    throw new ArcError(response.status, errorMessage);
  }
}

那么它会尝试重试来自 fetch 的任何 4xx 或 5xx 响应吗?我可以想象一些诸如 400(错误输入)错误之类的事情可能会跳过重试。而 429(太多的请求)将是回退的目的。还是我需要得到响应并决定显式抛出错误以使其重试?

4

0 回答 0