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

121
Vistas
Should I check if route params exist inside a controller?

I'm working on an Express app, and one of the routes looks like this

router.put(
  '/countries/:countryId/regions/:regionId/cities/:cityId',
  runAsyncWrapper(updateCity),
);

Inside the controller I have these checks

const {
    params: { countryId, regionId, cityId },
    body,
  } = req;
   if (!countryId) throw new CountryIdRequired();
   if (!regionId) throw new RegionIdRequired();
   if (!cityId) throw new CityIdRequired();

Do those checks even make any sense? Since these IDs are used in the route string, is there any chance that this controller (which is used only with that one route) will be called, and some of the params will be null or undefined?

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

0

Express should answer with HTTP 404 if your params are not set.

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