Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
Http Exception in try and catch blocks

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?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you are passing email that is not present in your database. pass valid email that present in your database.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda