From 95cc616552e7a040e67cb26e9b5d4a874be368aa Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Fri, 11 Apr 2025 17:43:42 +0000 Subject: [PATCH] Fix: Improve error handling and logging for undefined values in registration. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/616774c3-6728-4884-b1a3-da6f175f78f9.jpg --- server/routes.ts | 8 +++++++- server/storage.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index 0b206c0..e4214c8 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -991,6 +991,9 @@ export async function registerRoutes(app: Express): Promise { // Handle expiration date based on the expiresIn parameter const expiresIn = req.body.expiresIn || 'never'; + console.log("Processing expiresIn:", expiresIn); + console.log("Full request body for debugging:", req.body); + if (expiresIn !== 'never') { const now = new Date(); @@ -1003,6 +1006,7 @@ export async function registerRoutes(app: Express): Promise { const [year, month, day] = req.body.customDate.split('-').map(Number); if (isNaN(year) || isNaN(month) || isNaN(day)) { + console.log("Invalid date components:", { year, month, day }); throw new Error("Invalid date format. Expected YYYY-MM-DD"); } @@ -1035,13 +1039,15 @@ export async function registerRoutes(app: Express): Promise { tokenData.expiresAt = customDate; console.log("Final custom expiration date:", customDate.toISOString()); } else { + console.log("Missing customDate field in request"); throw new Error("Custom date is required for custom expiration"); } } catch (e) { console.error("Error parsing custom date:", e); return res.status(400).json({ message: "Invalid custom date or time", - details: e instanceof Error ? e.message : String(e) + details: e instanceof Error ? e.message : String(e), + requestBody: req.body }); } } else { diff --git a/server/storage.ts b/server/storage.ts index 8532b4b..ccb2ea9 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -505,15 +505,22 @@ export class MemStorage implements IStorage { // Handle expiresAt let expiresAt = null; if (token.expiresAt) { + console.log("Processing expiresAt from token:", token.expiresAt); if (token.expiresAt instanceof Date) { expiresAt = token.expiresAt; + console.log("expiresAt is a Date object:", expiresAt); } else if (typeof token.expiresAt === 'string') { try { expiresAt = new Date(token.expiresAt); + console.log("Parsed expiresAt from string:", expiresAt); } catch (e) { - console.error("Failed to parse expiresAt date string:", token.expiresAt); + console.error("Failed to parse expiresAt date string:", token.expiresAt, e); } + } else { + console.error("Unexpected expiresAt type:", typeof token.expiresAt); } + } else { + console.log("No expiresAt provided in token data"); } const newToken: ApiToken = {