Skip to content

Commit

Permalink
enh(api): enhance error handling in parser function to return structu…
Browse files Browse the repository at this point in the history
…red log message
  • Loading branch information
brnovasco committed Jan 27, 2025
1 parent 6a19292 commit a2d02cf
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions packages/api/src/router/console-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,42 @@ function parseInnerMessage(message: string): ParsedLogMessage | null {
const match = innerMessageRegex.exec(message);

if (!match) {
console.error("Failed to parse inner message:", message);
return null;
console.error("Failed to parse inner message:\n", message);
const now = new Date();
return {
logLevel: "U",
date: now.toISOString().slice(0, 10),
timestamp: now.toISOString().slice(11, 19),
service: "Unknown",
textMessage: message,
};
}

const [, bracketContent, textMessage] = match;
if (!bracketContent) {
console.error("Failed to parse bracket content:", message);
return null;
console.error("Failed to parse bracket content:\n", message);
const now = new Date();
return {
logLevel: "U",
date: now.toISOString().slice(0, 10),
timestamp: now.toISOString().slice(11, 19),
service: "Unknown",
textMessage: message,
};
}

const [logLevel, date, timestamp, service] = bracketContent.split(/\s+/);

if (!logLevel || !date || !timestamp || !service || !textMessage) {
console.error("Failed to parse bracket content:", message);
return null;
const now = new Date();
return {
logLevel: "U",
date: now.toISOString().slice(0, 10),
timestamp: now.toISOString().slice(11, 19),
service: "Unknown",
textMessage: message,
};
}

return {
Expand Down

0 comments on commit a2d02cf

Please sign in to comment.