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
This commit is contained in:
alphaeusmote
2025-04-11 17:43:42 +00:00
parent aee6e1ad74
commit 95cc616552
2 changed files with 15 additions and 2 deletions
+7 -1
View File
@@ -991,6 +991,9 @@ export async function registerRoutes(app: Express): Promise<Server> {
// 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<Server> {
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<Server> {
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 {
+8 -1
View File
@@ -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 = {