-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add examples for new JS config options, other minor cleanups
This commit adds a "config-and-error-handling" page for the node.js SDK, and in there we show some examples of how to use the succinct version of the constructor without specifying an explicit config. We also show an example of using the new `WithThrowOnErrors` configuration option. Also did a few other cleanups while I was in here, including: * add missing example code for Lambda configuration on Configurations page. * Remove all the "COMING SOON"s * Fixed the order of the `TopicClient` example on the topics API reference page. * Removed some redundant copies of stuff like 'observability' that was duplicated between "Topics" and "Cache" sections; but then gave up on this in favor of moving the "SDKs" stuff up to the top level in a subsequent PR after discussion with Allen.
- Loading branch information
Showing
38 changed files
with
72 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
docs/cache/develop/sdks/nodejs/config-and-error-handling.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
sidebar_position: 2 | ||
sidebar_label: Config and Error Handling | ||
title: Observability for TypeScript and Node.js | ||
description: Instrument your Momento-enabled Node.js code with Logs, Metrics, and Traces | ||
--- | ||
|
||
import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock"; | ||
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet | ||
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl | ||
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl"; | ||
|
||
# Configuration and Error Handling in the Momento node.js SDK | ||
|
||
## Configuration | ||
|
||
The code below illustrates the simplest way to construct a `CacheClient`: | ||
|
||
<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithNoConfig'} /> | ||
|
||
However, you may pass in a `Configuration` object to customize the behavior. | ||
|
||
Momento provides several pre-built configurations in the `Configurations` module, such as `InRegion` (which is configured | ||
with timeouts and connection counts that are appropriate for server-side connectivity from within the same AWS region), | ||
and `Lambda` (which is tuned for use in AWS Lambda environments). Here is how you can specify the `Lambda` configuration: | ||
|
||
<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithLambdaConfig'} /> | ||
|
||
If you omit the configuration, Momento will use the `Laptop` configuration by default. This configuration has relaxed | ||
timeouts, suitable for development or in high-latency environments. (It is not recommended for production, server-side use.) | ||
|
||
For more information about `Configuration` objects see [SDK Configuration Objects](/cache/develop/basics/client-configuration-objects.md). | ||
|
||
## Error Handling | ||
|
||
By default, `CacheClient` errors are surfaced to developers as part of the return values of the calls, as opposed to throwing | ||
exceptions. This makes errors more visible when you're writing your code, and allows your IDE to be more helpful in ensuring | ||
you've handled the errors you care about. | ||
|
||
Here's an example of how to check for errors on a `get` call: | ||
|
||
<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ErrorHandlingHitMiss'} /> | ||
|
||
However, if you prefer for exceptions to be thrown, you can configure the `CacheClient` to do so: | ||
|
||
<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithThrowOnErrorsConfig'} /> | ||
|
||
With this configuration setting, any errors that occur will result in an instance of `SdkError` being thrown. You may | ||
catch it and use its `.errorCode()` method to determine the specific error that occurred: | ||
|
||
<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ErrorHandlingExceptionErrorCode'} /> | ||
|
||
For more information about error handling in Momento see [SDK Error Handling](/cache/develop/basics/error-handling-production-readiness.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.