Skip to content

Commit 7921ff9

Browse files
bradmiroAce Nassri
authored andcommitted
fix: refactored request call to supress unhandled promise rejection (#406)
* Refactored request call to supress unhandled promise rejection and better error clarity * Latest suggestion for sample fix
1 parent dfbdd1d commit 7921ff9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

translate/v3/translate_create_glossary.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@ function main(
5353
glossary: glossary,
5454
};
5555

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

60-
// Wait for operation to complete.
61-
await operation.promise();
61+
// Wait for operation to complete.
62+
await operation.promise();
6263

63-
console.log(`Created glossary:`);
64-
console.log(`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`);
64+
console.log(`Created glossary:`);
65+
console.log(
66+
`InputUri ${request.glossary.inputConfig.gcsSource.inputUri}`
67+
);
68+
} catch (error) {
69+
console.error(error.details);
70+
}
6571
}
6672

6773
createGlossary();

0 commit comments

Comments
 (0)