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

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

0

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

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