I have a translation service which translates the strings thrown as an HTTP Exception. It works fine when it is not thrown inside a try{...} catch{...} block. But works outside of it.
async getEmployeeByEmail(emailRaw: string): Promise<Employee> {
try {
const employee = await this.employeeRepository.findOne({
relations: ['buildingAssignedAsLead'],
where: {
email: emailRaw,
},
});
if (!employee) {
return null;
}
return employee;
} catch (err) {
throw new HttpException(
'translations.EMAILS.INVALID_EMAIL',
HttpStatus.BAD_REQUEST,
);
}
}
I have an exception Response Filter which translates the message based on 'translations.EMAILS.INVALID_EMAIL' but while accessing the response from exception it is not getting the same string.
And hence it cannot be translated. When throwing httpException inside a catch block i get exception to be an object like :
{status: ..., message: Invalid Email, ...}
and when not throwing inside a catch block it comes like
translations.EMAILS.INVALID_EMAIL
What can be done to make catch block send the same response?
you are passing email that is not present in your database. pass valid email that present in your database.