Question:
I’m working on an Express app, and one of the routes looks like thisrouter.put(
'/countries/:countryId/regions/:regionId/cities/:cityId',
runAsyncWrapper(updateCity),
);
Inside the controller I have these checksconst {
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
?Answer:
Express should answer with HTTP 404 if your params are not set.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
If you like this answer, you can give me a coffee by click here (view Ads)
Leave a Review