Description
API routes and webhook handlers currently manage errors via disparate try/catch blocks. This lack of centralization creates a security risk where stack traces, internal database states, or environment variables could be leaked to the client during unhandled exceptions.
Proposed Solution
- Middleware Pattern: Create a higher-order wrapper function withErrorHandler in src/lib/middleware/.
- Sanitization: Implement logic that catches unhandled exceptions, sanitizes paths/stack traces, and scrubs process.env matches.
-Implementation: Wrap all exported GET and POST handlers in API routes with this middleware to ensure a uniform, secure JSON error response across the entire backend architecture.
Description
API routes and webhook handlers currently manage errors via disparate try/catch blocks. This lack of centralization creates a security risk where stack traces, internal database states, or environment variables could be leaked to the client during unhandled exceptions.
Proposed Solution
-Implementation: Wrap all exported GET and POST handlers in API routes with this middleware to ensure a uniform, secure JSON error response across the entire backend architecture.