diff --git a/apps/web/utils/gmail/draft.ts b/apps/web/utils/gmail/draft.ts index 93c584903e..180d97f2fa 100644 --- a/apps/web/utils/gmail/draft.ts +++ b/apps/web/utils/gmail/draft.ts @@ -60,7 +60,7 @@ export async function deleteDraft(gmail: gmail_v1.Gmail, draftId: string) { } logger.info("Successfully deleted draft", { draftId }); } catch (error) { - if (error instanceof Error && "code" in error && error.code === 404) { + if (isNotFoundError(error)) { logger.warn("Draft not found or already deleted, skipping deletion.", { draftId, }); diff --git a/apps/web/utils/outlook/draft.ts b/apps/web/utils/outlook/draft.ts index 5851dd6aff..2a3693ad8b 100644 --- a/apps/web/utils/outlook/draft.ts +++ b/apps/web/utils/outlook/draft.ts @@ -22,14 +22,7 @@ export async function getDraft({ return message; } catch (error) { if (isNotFoundError(error)) { - return null; - } - - // Handle Outlook's "object not found in the store" error - if ( - error instanceof Error && - error.message.includes("not found in the store") - ) { + logger.info("Draft not found, returning null.", { draftId }); return null; } @@ -67,11 +60,28 @@ export async function deleteDraft({ } function isNotFoundError(error: unknown): boolean { - const err = error as { statusCode?: number; code?: number | string }; - return ( + const err = error as { + statusCode?: number; + code?: number | string; + message?: string; + }; + + // Check error code + if ( err?.statusCode === 404 || err?.code === 404 || err?.code === "ErrorItemNotFound" || err?.code === "itemNotFound" - ); + ) { + return true; + } + + if ( + err?.message?.includes("not found in the store") || + err?.message?.includes("ErrorItemNotFound") + ) { + return true; + } + + return false; } diff --git a/version.txt b/version.txt index 7abc9a7c1b..86a47acef3 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.24.6 +v2.24.7