fix(api): properly resolve the promise if a callback throws an Error