unjs / ofetch

😱 A better fetch API. Works on node, browser and workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] how to get request options from the aborted request after all retries are performed and failed ?

geminigeek opened this issue · comments

hi,

i want to get the request options from the abort error message , when the request is aborted after all retries are performed. can anyone help?

const { headers, _data, ...rest } = await ofetch.raw(url, {
  method: "POST",
  body: { some: "value" },
  timeout: 2000, //ms
  retry: maxRetries,
  retryDelay: 1300, // ms
  ignoreResponseError: true,
  async onRequest(ctx) {
    // here i change some option values based on retry number
    // these values i am looking for in catch / error when request is aborted after all retries are performed
  },
})

thanks for reading

i figured it out, setting a key on error in "onRequestError" i can pass that to error