Enhance lock acquisition and error handling in worker service
- Implement retry logic for acquiring file lock with a maximum of 3 attempts. - Improve error handling for ENOENT errors by ensuring the directory exists before retrying. - Update context injection handler to delegate to SearchRoutes, reducing code duplication and preventing "headers already sent" errors. - Add checks for headersSent in error responses to avoid sending multiple responses. - Log warnings when the port does not free up after shutdown, and handle forced shutdown scenarios more gracefully.
This commit is contained in:
@@ -74,9 +74,12 @@ export abstract class BaseRouteHandler {
|
||||
|
||||
/**
|
||||
* Centralized error logging and response
|
||||
* Checks headersSent to avoid "Cannot set headers after they are sent" errors
|
||||
*/
|
||||
protected handleError(res: Response, error: Error, context?: string): void {
|
||||
logger.failure('WORKER', context || 'Request failed', {}, error);
|
||||
res.status(500).json({ error: error.message });
|
||||
if (!res.headersSent) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user