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

182
Views
¿Cómo arrojar un error dentro de la consulta del grupo pg en Express JS?

Tengo problemas cuando trato de generar un error (para marcar si no hay un nombre de usuario) dentro de la consulta del grupo. Lo que espero es que checkUsername el error y lo convierta en una respuesta json estándar. Pero, siempre recibo un error como este:

error de detalles

Aquí está mi código en el controlador:

 const checkUsername = (req, res) => { const service = new AuthService() try { service.chekcUsernameIsExist(req.body.username, res) return res.status(200).send('Username is exist') } catch (error) { const response = { status: false, message: error.message, error_code: 400 } return res.status(400).send(response) } }

Y aquí está mi código en servicio:

 class AuthService { chekcUsernameIsExist (username) { const query = `select * from admins where username = '${username}';` pool.query(query, (err, results, release) => { if (err) { throw err } else if (results.rowCount !== 0) { console.log('Username is exist') } else { console.log('Username is not exist') throw new Error('Username is not exist') } }) } }

Intento agregar el bloque try catch dentro checkUsernameIsExist pero sigo teniendo el mismo problema. En el estúpido, agrego una variable a la que tiene valor 1, 2 o 3 para marcar si el nombre de usuario existe, no existe u otro error.

about 4 years ago · Juan Pablo Isaza
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!