Skip to content

Commit

Permalink
chore: use the .value() syntax in the ThrowOnErrors example
Browse files Browse the repository at this point in the history
The combination of the new `.value()` accessors and the `WithThrowOnErrors`
config allows users to write code that doesn't do any `instanceof` checks.
That is probably the more idiomatic combination for cases where users are
doing `ThrowOnError`. This commit updates the ThrowOnError example code
to use `.value()`, accordingly.
  • Loading branch information
cprice404 committed Jan 18, 2024
1 parent 3c095f3 commit 5f2ce67
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async function example_configuration_ConstructWithThrowOnErrorsConfig() {

async function example_configuration_ErrorHandlingExceptionErrorCode(cacheClient: CacheClient) {
try {
const result = await cacheClient.get('test-cache', 'test-key');
if (result instanceof CacheGet.Hit) {
console.log(`Retrieved value for key 'test-key': ${result.valueString()}`);
} else if (result instanceof CacheGet.Miss) {
const result = (await cacheClient.get('test-cache', 'test-key')).value();
if (result !== undefined) {
console.log(`Retrieved value for key 'test-key': ${result}`);
} else {
console.log("Key 'test-key' was not found in cache 'test-cache'");
}
} catch (e) {
Expand Down

0 comments on commit 5f2ce67

Please sign in to comment.