mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-16 17:16:19 +00:00
refactor: bare structure for new backend architecture and runtime; no behavior changes yet
This commit is contained in:
19
server/src/shared/utils/app-error.ts
Normal file
19
server/src/shared/utils/app-error.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export type AppErrorOptions = {
|
||||
code?: string;
|
||||
statusCode?: number;
|
||||
details?: unknown;
|
||||
};
|
||||
|
||||
export class AppError extends Error {
|
||||
readonly code: string;
|
||||
readonly statusCode: number;
|
||||
readonly details?: unknown;
|
||||
|
||||
constructor(message: string, options: AppErrorOptions = {}) {
|
||||
super(message);
|
||||
this.name = 'AppError';
|
||||
this.code = options.code ?? 'INTERNAL_ERROR';
|
||||
this.statusCode = options.statusCode ?? 500;
|
||||
this.details = options.details;
|
||||
}
|
||||
}
|
||||
32
server/src/shared/utils/logger.ts
Normal file
32
server/src/shared/utils/logger.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
type LoggerLevel = 'info' | 'warn' | 'error';
|
||||
|
||||
function formatMetadata(metadata?: Record<string, unknown>): string {
|
||||
if (!metadata || Object.keys(metadata).length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return ` ${JSON.stringify(metadata)}`;
|
||||
}
|
||||
|
||||
function write(level: LoggerLevel, message: string, metadata?: Record<string, unknown>): void {
|
||||
const prefix = `[server:${level}]`;
|
||||
const formatted = `${prefix} ${message}${formatMetadata(metadata)}`;
|
||||
|
||||
if (level === 'error') {
|
||||
console.error(formatted);
|
||||
return;
|
||||
}
|
||||
|
||||
if (level === 'warn') {
|
||||
console.warn(formatted);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(formatted);
|
||||
}
|
||||
|
||||
export const logger = {
|
||||
info: (message: string, metadata?: Record<string, unknown>) => write('info', message, metadata),
|
||||
warn: (message: string, metadata?: Record<string, unknown>) => write('warn', message, metadata),
|
||||
error: (message: string, metadata?: Record<string, unknown>) => write('error', message, metadata),
|
||||
};
|
||||
Reference in New Issue
Block a user