vlio20 / utils-decorators

Decorators for web and node applications
https://vlio20.github.io/utils-decorators/
MIT License
216 stars 13 forks source link

[timeout decorator] Should catch the original exception if the method throw an error before timeout #143

Closed gongpeione closed 2 years ago

gongpeione commented 2 years ago

Hi, I am sorry for being late, I think these decorators you provide are super useful, but I have a little problem when I use the timeout decorator, if the method throw an error before timeout, I cannot catch the original error but timeout error.

Example code:

const ms = 50;

class T {
  @timeout(ms)
  async foo() {
    await Promise.reject(1);
    await sleep(100);
  }
}

const t = new T();

try {
  await t.foo();
} catch (e) {
  console.log(e);
}

Current output : [Error: timeout occurred after 50] Expect output : 1

Linked pull request: #142

vlio20 commented 2 years ago

issue resolved in 2.0.4. Thanks @gongpeione