unjs / ofetch

😱 A better fetch API. Works on node, browser and workers.
MIT License
4.15k stars 128 forks source link

Errors not forwarded in hooks #148

Closed wagpa closed 2 months ago

wagpa commented 2 years ago

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"
  }
})
Hebilicious commented 1 year ago

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 ?

pi0 commented 2 months ago

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