Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit d23cd60

Browse files
committed
chore: improves documentation and error handling
Improves documentation for accuracy and clarity by updating descriptions and correcting code examples. Adds error handling to code examples to enhance robustness. Refactors file copy command in custom containers documentation for correctness.
1 parent 81bf170 commit d23cd60

File tree

10 files changed

+76
-27
lines changed

10 files changed

+76
-27
lines changed

docs/architecture/websites.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ classDef edgeLabel line-height:2;
5050
flowchart TD
5151
Developer["Developer"]
5252
NitricUp["nitric up"]
53-
Storage["Azure Storage"]
53+
BlobStorage["Azure Blob Storage"]
5454
FrontDoor["Azure Front Door"]
5555
Rewrite["Azure API Management"]
5656
5757
Developer -->|Deploy| NitricUp
58-
NitricUp -->|Upload Assets| Storage
58+
NitricUp -->|Upload Assets| BlobStorage
5959
NitricUp -->|Create CDN| FrontDoor
60-
FrontDoor -->|Serve Static Files| Storage
60+
FrontDoor -->|Serve Static Files| BlobStorage
6161
FrontDoor -->|Rewrite /api/* to API| Rewrite
6262
6363
classDef default line-height:1;

docs/reference/custom-containers.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RUN apt-get update -y && \
6161
RUN pip install --upgrade pip pipenv
6262
6363
# Copy either requirements.txt or Pipfile
64-
COPY requirements.tx[t] Pipfil[e] Pipfile.loc[k] ./
64+
COPY requirements.txt Pipfile Pipfile.lock ./
6565
6666
# Guarantee lock file if we have a Pipfile and no Pipfile.lock
6767
RUN (stat Pipfile && pipenv lock) || echo "No Pipfile found"

docs/reference/env.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Nitric sets a number of environment variables to help you manage your project. T
1010

1111
If you are running your project in the cloud, build, or the run environment, Nitric provides prefixed Environment Variables, which you can find in the table below.
1212

13-
| Name | Description |
14-
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
15-
| NITRIC_STACK_ID | The Stack ID of the project. Example: `coolkat-gcp-4c0wg0hg` |
16-
| NITRIC_ENVIRONMENT | The Environment that the app is running on. The value can be either `cloud` (for deployed in the cloud), `run` (for stacks running in nitric run), or `build` (for stack code running during the deployment gathering phase). |
13+
| Name | Description |
14+
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
15+
| NITRIC_STACK_ID | The unique identifier for your deployed stack (e.g., `coolkat-gcp-4c0wg0hg`) |
16+
| NITRIC_ENVIRONMENT | The environment where the app is running: `cloud` (deployed), `run` (local stack), or `build` (during deployment) |
1717

1818
## Application Environment Variables
1919

docs/reference/nodejs/secrets/secret-put.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ import { secret } from '@nitric/sdk'
4040

4141
const keyRef = secret('apiKey').allow('put')
4242

43-
await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
43+
try {
44+
await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
45+
console.log('Secret value stored successfully')
46+
} catch (error) {
47+
console.error('Error storing secret value:', error)
48+
}
4449
```
4550

4651
### Get the id of a new secret version
@@ -52,9 +57,10 @@ import { secret } from '@nitric/sdk'
5257

5358
const keyRef = secret('apiKey').allow('put')
5459

55-
const newApiKeyVersionRef = await keyRef.put(
56-
'6c3199a3-094e-4797-bfc9-9ee2a7839286',
57-
)
58-
59-
const versionId = newApiKeyVersionRef.version
60+
try {
61+
const newVersion = await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
62+
console.log('New secret version created:', newVersion.version)
63+
} catch (error) {
64+
console.error('Error creating new secret version:', error)
65+
}
6066
```

docs/reference/nodejs/sql/sql-connection-string.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ import { sql } from '@nitric/sdk'
3030
const db = sql('my-data')
3131

3232
// Should be called at runtime, such as in a service handler
33-
const connStr = await db.connectionString()
33+
try {
34+
const connStr = await db.connectionString()
35+
console.log('Database connection string:', connStr)
36+
} catch (error) {
37+
console.error('Error getting connection string:', error)
38+
}
3439
```
3540

3641
### Connect with Prisma

docs/reference/nodejs/storage/bucket-file-read.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ const assets = bucket('assets').allow('read')
3232

3333
const logo = assets.file('images/logo.png')
3434

35-
const logoData = await logo.read()
35+
try {
36+
const logoData = await logo.read()
37+
console.log('Logo data:', logoData)
38+
} catch (error) {
39+
console.error('Error reading logo:', error)
40+
}
3641
```

docs/reference/nodejs/storage/bucket-file-write.mdx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ import { bucket } from '@nitric/sdk'
1717
const assets = bucket('assets').allow('write')
1818

1919
const logo = assets.file('images/logo.png')
20-
21-
await logo.write(someImageData)
20+
const imageData = new Uint8Array([
21+
/* image data */
22+
])
23+
24+
try {
25+
await logo.write(imageData)
26+
console.log('Logo written successfully')
27+
} catch (error) {
28+
console.error('Error writing logo:', error)
29+
}
2230
```
2331

2432
## Parameters
@@ -41,5 +49,10 @@ const assets = bucket('assets').allow('write')
4149
const txt = assets.file('my-text-file.txt')
4250
const buffer = Buffer.from('My Test File...')
4351

44-
await txt.write(buffer)
52+
try {
53+
await txt.write(buffer)
54+
console.log('Text file written successfully')
55+
} catch (error) {
56+
console.error('Error writing text file:', error)
57+
}
4558
```

docs/reference/nodejs/storage/bucket-on.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ assets.on('write', '/images/cat', (ctx) => {
2929

3030
// If `on` is called with a permissioned bucket, a file will also be provided with the request
3131
accessibleAssets.on('write', '/images/dog', async (ctx) => {
32-
const dogImage = await ctx.req.file.read()
33-
34-
console.log(dogImage)
32+
try {
33+
const dogImage = await ctx.req.file.read()
34+
console.log(dogImage)
35+
} catch (error) {
36+
console.error('Error reading dog image:', error)
37+
}
3538
})
3639
```
3740

docs/reference/nodejs/websocket/websocket-on.mdx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ const socket = websocket('socket')
7878
const connections = kv('connections').allow('get', 'set', 'delete')
7979

8080
socket.on('connect', async (ctx) => {
81-
const connectionList = await connections.get('connections')
82-
await connections..set('connections', [
81+
let connectionList = []
82+
try {
83+
connectionList = await connections.get('connections')
84+
} catch (e) {
85+
console.log('Creating new connections store')
86+
}
87+
await connections.set('connections', [
8388
...connectionList,
8489
{
8590
// store any metadata related to the connection here
@@ -89,10 +94,16 @@ socket.on('connect', async (ctx) => {
8994
})
9095

9196
socket.on('disconnect', async (ctx) => {
92-
const connectionList = await connections.get('connections')
97+
let connectionList = []
98+
try {
99+
connectionList = await connections.get('connections')
100+
} catch (e) {
101+
console.log('No connections found')
102+
return
103+
}
93104
await connections.set(
94105
'connections',
95-
connectionList.filter((c) => c.connectionId === ctx.req.connectionId)
106+
connectionList.filter((c) => c.connectionId === ctx.req.connectionId),
96107
)
97108
})
98109
```

docs/reference/nodejs/websocket/websocket-send.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ socket.on('disconnect', async (ctx) => {
7777
})
7878

7979
const broadcast = async (data) => {
80-
const conns = await connections.get('connections')
80+
let conns = {}
81+
try {
82+
conns = await connections.get('connections')
83+
} catch (e) {
84+
console.log('No connections found')
85+
return
86+
}
8187

8288
await Promise.all(
8389
Object.keys(conns).map(async (connectionId) => {

0 commit comments

Comments
 (0)