logger.log() info logslogger.warn() warning logslogger.error() error logsconsole.log() debug output// Get embeddings for texts
async getEmbeddings(texts: string[]): Promise<number[][]> {
this.logger.log(`Getting embeddings for ${texts.length} texts`);
try {
// Call API to get embeddings
const response = await this.callEmbeddingAPI(texts);
return response.data;
} catch (error) {
this.logger.error('Failed to get embeddings', error);
// Use i18n for user-facing error messages
throw new Error(this.i18n.t('errors.embeddingGenerationFailed'));
}
}
import { I18nService } from './i18n.service';
async processDocument(file: Express.Multer.File) {
try {
// Process document...
return result;
} catch (error) {
// Error message in user's selected language
throw new Error(this.i18n.t('errors.documentProcessingFailed', {
filename: file.originalname
}));
}
}
The @MinLength, @MaxLength, @IsEmail, etc. decorators from class-validator have a static message property that cannot access NestJS's I18nService at runtime. Therefore:
DO NOT use hardcoded messages in validation decorators like:
@MinLength(8, { message: 'Password must be at least 8 characters long' })
DO perform validation in the controller layer with i18n support:
if (password.length < 6) {
throw new BadRequestException(this.i18nService.getErrorMessage('passwordMinLength'));
}
OR remove the decorator and rely on controller-level validation only
When adding new validation to DTOs, ensure validation messages are internationalized by:
server/src/i18n/messages.tsI18nService