Performance: Custom exception classes
MEDIUM IMPACT
This affects server response time and error handling efficiency, impacting how fast error responses are generated and sent to clients.
import { HttpException, HttpStatus } from '@nestjs/common'; export class UserNotFoundException extends HttpException { constructor() { super('User not found', HttpStatus.NOT_FOUND); } } throw new UserNotFoundException();
throw new Error('User not found');| Pattern | CPU Overhead | Error Handling Complexity | Response Size | Verdict |
|---|---|---|---|---|
| Generic Error | Low but requires extra parsing | High due to unstructured messages | Minimal | [!] OK |
| Custom Exception Class | Minimal and structured | Low due to clear error types | Slightly larger but optimized | [OK] Good |