Consistent error handling across the Brain-Storm backend using error hierarchy and factory pattern.
new AppError(code, message, statusCode, details)ValidationError(400) - Input validation failuresAuthenticationError(401) - Auth failuresAuthorizationError(403) - Permission deniedNotFoundError(404) - Resource not foundConflictError(409) - Resource conflictStellarError(500) - Blockchain operationsDatabaseError(500) - Database operations
import { ErrorFactory } from '@/common/errors/error.factory';
// Validation
throw ErrorFactory.validation('Invalid email', { field: 'email' });
// Not found
throw ErrorFactory.notFound('User');
// Stellar operation
throw ErrorFactory.stellar('Transaction failed', { txHash: '...' });Automatically catches all errors and returns standardized JSON:
{
"statusCode": 400,
"code": "VALIDATION_ERROR",
"message": "Invalid email",
"details": { "field": "email" },
"timestamp": "2026-05-29T11:51:05.034Z"
}- Always use ErrorFactory for consistency
- Include relevant details for debugging
- Log errors appropriately
- Return meaningful messages to clients
- Use specific error types, not generic AppError