Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Fix invalid JavaScript in readme example
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kentonv committed Jun 4, 2020
1 parent 7470501 commit efb0640
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ async function handleEvent(event) {
try {
return await getAssetFromKV(event)
} catch (e) {
switch (typeof resp) {
case NotFoundError:
//..
case MethodNotAllowedError:
// ...
default:
return new Response("An unexpected error occurred", { status: 500 })
}
if (e instanceof NotFoundError) {
// ...
} else if (e instanceof MethodNotAllowedError) {
// ...
} else {
return new Response("An unexpected error occurred", { status: 500 })
}
}
} else return fetch(event.request)
Expand Down Expand Up @@ -190,4 +188,4 @@ A custom handler for mapping requests to a single root: `index.html`. The most c
import { getAssetFromKV, serveSinglePageApp } from '@cloudflare/kv-asset-handler'
...
let asset = await getAssetFromKV(event, { mapRequestToAsset: serveSinglePageApp })
```
```

0 comments on commit efb0640

Please sign in to comment.