Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda