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

226
Views
Buenas prácticas de JS: ¿Crear excepciones relacionadas con las fábricas?

¿Es una "buena práctica" crear errores relacionados con un mismo concepto a través de fábrica?

Quiero decir, por ejemplo, en una validación de registro, ¿podría ser una buena práctica hacer lo siguiente?

 "use strict"; const { functions } = require("../../../services/firebase") const authErrors = Object.freeze({ invalidPassword() { return new functions.https.HttpsError( "invalid-argument", "Invalid password.", { status: "error", code: "auth/invalid-password", message: "The provided password is invalid. It must contain between 8 and 40 characters, including at least one uppercase letter, one lowercase letter, and a number.", } ); }, invalidUsername() { return new functions.https.HttpsError( "invalid-argument", "Invalid username.", { status: "error", code: "auth/invalid-username", message: "Username must be between 3 and 30 characters, including numbers, letters, hyphens, periods, or underscores.", } ); }, // ... more related errors }); module.exports = authErrors;

y luego usarlos de la siguiente manera?

 if (!validateUsername(username)) { throw authErrors.invalidUsername(); }

Nota: Estoy usando Google Cloud Functions y no tiene sentido que mi caso de uso arroje instancias de errores personalizados.

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!