@unofficialbox/box-open-sdk 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/errors.md +35 -3
- package/package.json +1 -1
package/docs/errors.md
CHANGED
|
@@ -12,10 +12,42 @@ and the raw `body`; transport and decode failures carry the underlying
|
|
|
12
12
|
```ts
|
|
13
13
|
import { runtime } from '@unofficialbox/box-open-sdk';
|
|
14
14
|
try {
|
|
15
|
-
await client.files.
|
|
15
|
+
await client.files.get(fileId);
|
|
16
16
|
} catch (err) {
|
|
17
|
-
if (err instanceof runtime.BoxApiError) {
|
|
18
|
-
// err.status, err.code, err.boxMessage, err.requestId, err.body, err.cause
|
|
17
|
+
if (err instanceof runtime.BoxApiError) {
|
|
18
|
+
// err.status, err.code, err.boxMessage, err.requestId, err.body, err.cause
|
|
19
|
+
}
|
|
19
20
|
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Etags: `If-None-Match` and `If-Match`
|
|
24
|
+
|
|
25
|
+
Files and folders carry an `etag`. Send it back to stay in sync with Box
|
|
26
|
+
(Box's [Ensure consistency](https://developer.box.com/guides/api-calls/ensure-consistency/)
|
|
27
|
+
guide):
|
|
28
|
+
|
|
29
|
+
- **Reads** — pass the stored etag as `if-none-match` on a file or folder
|
|
30
|
+
`get` (or a shared-item lookup). Box answers `304 Not Modified` when
|
|
31
|
+
nothing changed, and the SDK raises it as the error above with status
|
|
32
|
+
`304`: keep your cached copy.
|
|
33
|
+
- **Writes** — pass it as `if-match` on a file or folder update or delete,
|
|
34
|
+
or a new file version upload. Box answers `412 Precondition Failed`
|
|
35
|
+
(code `precondition_failed`) when the item changed since you read it:
|
|
36
|
+
read it again, reapply your change, retry. `If-Match` can't block a move.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
try {
|
|
40
|
+
await client.files.get(fileId, { 'if-none-match': etag });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (err instanceof runtime.BoxApiError && err.status === 304) {
|
|
43
|
+
// unchanged since etag
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await client.files.update(fileId, body, { 'if-match': etag });
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (err instanceof runtime.BoxApiError && err.status === 412) {
|
|
50
|
+
// changed since etag: re-read and retry
|
|
51
|
+
}
|
|
20
52
|
}
|
|
21
53
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unofficialbox/box-open-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Box API client for TypeScript (open source, community, punk rock) — typed models, async managers, and a fetch runtime with retry, backoff, and token refresh.",
|
|
5
5
|
"keywords": ["box", "box-api", "sdk", "api-client", "typescript", "unofficial"],
|
|
6
6
|
"license": "MIT",
|