0

I'm using Promise.reject

I've got this warning: Unhandled promise rejection warning: version 1.1 is not released

how can I solve this warning ?

Thanks for your help

public async retrieveVersionFromJira(versionName: string): Promise<ReleaseVersion> {
        const searchVersionsUri = config.jiraApiUri + 'versions';
        const jsonResp = await this.jiraClient.get(searchVersionsUri);
        const version: any = jsonResp.find(version => {
            if (version.name == versionName) {
                if (version.released == true) {
                    return Promise.reject("version " + versionName + " is not released");
                }
            }
        });
        if (!version) {
            return Promise.reject("missing version " + versionName + " on jira");
        }
        return new ReleaseVersion(version.id, version.name, version.released);
    }
jeremy
  • 165
  • 10
  • When you call your function you need to use a `try/catch` block if using `async/await` or a `.catch()` handler if using the Promise directly. – Jared Smith Aug 28 '19 at 15:17

2 Answers2

0

When you call your function you need to use a try/catch block if using async/await or a .catch() handler if using the Promise directly:

try {
  const answr = await retrieveVersionFromJira('1.1');
} catch (error) {
  console.error(error);
}

// alternatively
retrieveVersionFromJira('1.1').catch(console.error);
Jared Smith
  • 19,721
  • 5
  • 45
  • 83
0

Wherever you call this function, you don't either have a .catch in the promise chain, or try / catch around await retrieveVersionFromJira(...) in async context.

That is, the promise gets rejected, but there's no code to handle the rejection, your code ignores it and proceeds. The runtime warns you about that.

9000
  • 39,899
  • 9
  • 66
  • 104