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 Dec 16, 2019
1 parent a52c36b commit 02371ed
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 02371ed

Please sign in to comment.