Skip to content

Commit

Permalink
refactor: throw err for null KV namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bharati-21 committed Oct 1, 2023
1 parent 2a012f1 commit 40a854b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/handlers/scheduledEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export async function ping(env: env) {

export async function callDiscordNicknameBatchUpdate(env: env) {
const namespace = env[NAMESPACE_NAME] as unknown as KVNamespace;
let lastNicknameUpdate: string | number = 0;
let lastNicknameUpdate: string | number | null = 0;
try {
lastNicknameUpdate = (await namespace.get(DISCORD_NICKNAME_CHANGED_TIMESTAMP)) ?? 0;
lastNicknameUpdate = await namespace.get(DISCORD_NICKNAME_CHANGED_TIMESTAMP);
if (lastNicknameUpdate === null) {
throw new Error('Error while fetching KV "DISCORD_NICKNAME_CHANGED_TIMESTAMP"');
}
} catch (err) {
console.log('Error while fetching the timestamp for last nickname update');
throw err;
Expand Down

0 comments on commit 40a854b

Please sign in to comment.