Initial commit: Complete NodeJS-native setup

- Migrated from Python pre-commit to NodeJS-native solution
- Reorganized documentation structure
- Set up Husky + lint-staged for efficient pre-commit hooks
- Fixed Dockerfile healthcheck issue
- Added comprehensive documentation index
This commit is contained in:
William Valentin
2025-09-06 01:42:48 -07:00
commit e48adbcb00
159 changed files with 24405 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { NextFunction, Request, Response } from 'express';
/**
* Custom AuthError class that extends Error with HTTP status code
* Security: Provides consistent error handling for authentication issues
*/
export class AuthError extends Error {
statusCode: number;
constructor(message: string, statusCode: number = 401) {
super(message);
this.statusCode = statusCode;
this.name = 'AuthError';
}
}
/**
* Middleware to handle AuthError exceptions
* Security: Centralized error handling for authentication errors
*/
export const handleAuthError = (
err: Error,
req: Request,
res: Response,
next: NextFunction
) => {
if (err instanceof AuthError) {
return res.status(err.statusCode).json({
error: err.message,
statusCode: err.statusCode,
});
}
// Handle JWT verification errors
if (err.name === 'JsonWebTokenError' || err.name === 'TokenExpiredError') {
return res.status(401).json({
error: 'Invalid or expired token',
statusCode: 401,
});
}
next(err);
};