ofetch icon indicating copy to clipboard operation
ofetch copied to clipboard

Errors not forwarded in hooks

Open wagpa opened this issue 3 years ago • 1 comments

When an error occurs in the onRequest hook, the error is not shown in the console and no request is send. I would expect an error that occurs in the hook to still be shown in the console.

The following will create a fetch object that makes no requests, but prints no error.

$fetch.create({
  async onRequest(ctx): Promise<void> {
    throw "debug error"
  }
})

wagpa avatar Oct 21 '22 21:10 wagpa

The following code is working properly and logs "debug error 1" :

  const f = $fetch.create({
    onRequest(ctx): Promise<void> {
      throw "debug error 1";
    },
  });
  await f("http://httpstat.us/500");

@HydrofinLoewenherz Is this the behaviour that you expect ?

Hebilicious avatar Aug 08 '23 12:08 Hebilicious

Let's track via https://github.com/unjs/ofetch/issues/396

pi0 avatar Aug 28 '24 10:08 pi0