mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 20:23:36 +00:00
refactor: centralize error handling utilities across route modules
- Introduced a new common utility module for error handling, providing consistent methods for retrieving error messages and logging errors. - Updated individual route modules to utilize the shared error handling functions, reducing code duplication and improving maintainability. - Ensured all routes now log errors in a standardized format, enhancing debugging and monitoring capabilities.
This commit is contained in:
24
apps/server/src/routes/common.ts
Normal file
24
apps/server/src/routes/common.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Common utilities shared across all route modules
|
||||
*/
|
||||
|
||||
import { createLogger } from "../lib/logger.js";
|
||||
|
||||
type Logger = ReturnType<typeof createLogger>;
|
||||
|
||||
/**
|
||||
* Get error message from error object
|
||||
*/
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : "Unknown error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a logError function for a specific logger
|
||||
* This ensures consistent error logging format across all routes
|
||||
*/
|
||||
export function createLogError(logger: Logger) {
|
||||
return (error: unknown, context: string): void => {
|
||||
logger.error(`❌ ${context}:`, error);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user