Skip to content

Commit

Permalink
refactor: update timestamp only when no unsuccessful updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bharati-21 authored Dec 9, 2023
1 parent 966c509 commit a6a313e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/handlers/scheduledEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ export async function callDiscordNicknameBatchUpdate(env: env) {
}

const data: NicknameUpdateResponseType = await response.json();
if (data?.data.totalUsersStatus !== 0 && data?.data.successfulNicknameUpdates === 0) {
throw new Error("Error while trying to update users' discord nickname");
if (data?.data.unsuccessfulNicknameUpdates === 0) {
try {
await namespace.put('DISCORD_NICKNAME_UPDATED_TIME', Date.now().toString());
} catch (err) {
console.error('Error while trying to update the last nickname change timestamp');
}
}

console.log(data);

try {
await namespace.put('DISCORD_NICKNAME_UPDATED_TIME', Date.now().toString());
} catch (err) {
console.error('Error while trying to update the last nickname change timestamp');
}

return data;
}

0 comments on commit a6a313e

Please sign in to comment.