Skip to content

cloudflare KV tutorial page script text issue #25193

@YamateKyuko

Description

@YamateKyuko

Existing documentation URL(s)

https://developers.cloudflare.com/kv/get-started/

What changes are you suggesting?

javascript and typescript code in step 5 should be updated.
USERS_NOTIFICATION_CONFIG is used as name of namespace in whale page but in this code USER_NOTIFICATION is used.
This is a bit terrible for copy and paste users who tests sources before development like me.

Please change like this:

export interface Env {
  USERS_NOTIFICATION_CONFIG: KVNamespace;
}

export default {
  async fetch(request, env, ctx): Promise<Response> {
    try {
      // return new Response('Hello')
      await env.USERS_NOTIFICATION_CONFIG.put("user_2", "disabled");
      const value = await env.USERS_NOTIFICATION_CONFIG.get("user_2");
      if (value === null) {
        return new Response("Value not found", { status: 404 });
      }
      return new Response(value);
    } catch (err) {
      console.error(`KV returned error:`, err);
      const errorMessage =
        err instanceof Error
          ? err.message
          : "An unknown error occurred when accessing KV storage";
      return new Response(errorMessage, {
        status: 500,
        headers: { "Content-Type": "text/plain" },
      });
    }
  },
} satisfies ExportedHandler<Env>;

Sorry for bad English.

Thank you.

Additional information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions