Error handling
Authentify It implements a centralized and structured error handling strategy to ensure system resilience, developer observability, and client transparency.
General Methods
import { ExceptionFilter, Catch, ArgumentsHost, HttpException, HttpStatus, Logger } from '@nestjs/common';
@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
private readonly logger = new Logger(AllExceptionsFilter.name);
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status =
exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
const message =
exception instanceof HttpException ? exception.getResponse() : exception;
// Log error internally (can be sent to Sentry, Slack, etc.)
this.logger.error(`Error occurred: ${JSON.stringify(message)}`);
// Return safe error response to client
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
message,
});
}
}Error Types
Last updated