Skip to content

Commit

Permalink
fix: refactored request call to supress unhandled promise rejection (#…
Browse files Browse the repository at this point in the history
…406)

* Refactored request call to supress unhandled promise rejection and better error clarity

* Latest suggestion for sample fix
  • Loading branch information
bradmiro authored and Ace Nassri committed Nov 17, 2022
1 parent 4665149 commit f9bf690
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions translate/v3/translate_create_glossary.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ function main(
glossary: glossary,
};

// Create glossary using a long-running operation.
// You can wait for now, or get results later.
const [operation] = await translationClient.createGlossary(request);
// Create glossary using a long-running operation
// and wait for its completion
try {
const [operation] = await translationClient.createGlossary(request);

// Wait for operation to complete.
await operation.promise();
// Wait for operation to complete.
await operation.promise();

console.log(`Created glossary:`);
console.log(`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`);
console.log(`Created glossary:`);
console.log(
`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`
);
} catch (error) {
console.error(error.details);
}
}

createGlossary();
Expand Down

0 comments on commit f9bf690

Please sign in to comment.