Skip to content

Commit 6a5184b

Browse files
kentonvGregBrimble
authored andcommitted
Fix invalid JavaScript in readme example
This switch/typeof example isn't valid JavaScript AFAICT -- JS doesn't have "type switches" like Go does. NOTE: Unfortunately this example still won't work, because NotFoundError and MethodNotAllowedError are not imported. It doesn't look like kv-asset-handler exports these types currently, so I guess a code change is needed to export them? See #93 (not fully fixed by this PR)
1 parent a3d14b3 commit 6a5184b

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

packages/kv-asset-handler/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ async function handleEvent(event) {
6262
try {
6363
return await getAssetFromKV(event)
6464
} catch (e) {
65-
switch (typeof resp) {
66-
case NotFoundError:
67-
//..
68-
case MethodNotAllowedError:
69-
// ...
70-
default:
71-
return new Response("An unexpected error occurred", { status: 500 })
72-
}
65+
if (e instanceof NotFoundError) {
66+
// ...
67+
} else if (e instanceof MethodNotAllowedError) {
68+
// ...
69+
} else {
70+
return new Response("An unexpected error occurred", { status: 500 })
7371
}
7472
}
7573
} else return fetch(event.request)
@@ -190,4 +188,4 @@ A custom handler for mapping requests to a single root: `index.html`. The most c
190188
import { getAssetFromKV, serveSinglePageApp } from '@cloudflare/kv-asset-handler'
191189
...
192190
let asset = await getAssetFromKV(event, { mapRequestToAsset: serveSinglePageApp })
193-
```
191+
```

0 commit comments

Comments
 (0)