How to catch errors from a chain of async functions of a third party library?

Viewed 24

I need to catch an error from a third party library.

(async () => {

    try {
        var response = await func_1();
        console.log("should not show this");
    }
    catch (err) {
        console.log("should show this", err);
    }

    async function func_1() {
        func_2();
    }

    async function func_2() {
        func_N();
    }

    async function func_N() {
        throw new Error("oops");
    }
    
})();

So I need to catch func_N error in try catch but becuase func_N is async and it's called by some functions without await the try catch doesn't catch the error.

So is there any way to do this?

1 Answers

func_N is async and it's called by some functions without await
(and without return)

Then they need to fix that. There's nothing you can do about this otherwise.

Related