Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!