diff --git a/src/routes/categories.ts b/src/routes/categories.ts index 9f9176f..9c37085 100644 --- a/src/routes/categories.ts +++ b/src/routes/categories.ts @@ -12,5 +12,11 @@ export default async function categories(fastify: FastifyInstance) { // get the category by provided id fastify.get<{ Params: CategoryParams - }>('/categories/:id', async (req) => RECIPE_CATEGORIES.find(recipeCategory => recipeCategory.id === parseInt(req.params.id))) + }>('/categories/:id', async (req, reply) => { + const recipeCategory = RECIPE_CATEGORIES.find(recipeCategory => recipeCategory.id === parseInt(req.params.id)) + if(!recipeCategory) { + reply.code(404).type('text/html').send('Not Found') + } + return recipeCategory + }) } diff --git a/src/routes/recipes.ts b/src/routes/recipes.ts index c1628f5..a397f4a 100644 --- a/src/routes/recipes.ts +++ b/src/routes/recipes.ts @@ -35,5 +35,11 @@ export default async function recipes(fastify: FastifyInstance) { // get the recipe by provided id fastify.get<{ Params: RecipeParams - }>('/recipes/:id', async (req) => RECIPES.find(recipe => recipe.id === parseInt(req.params.id))) + }>('/recipes/:id', async (req, reply) => { + const recipe = RECIPES.find(recipe => recipe.id === parseInt(req.params.id)) + if(!recipe) { + reply.code(404).type('text/html').send('Not Found') + } + return recipe + }) } diff --git a/src/routes/users.ts b/src/routes/users.ts index c24ffd8..819b86e 100644 --- a/src/routes/users.ts +++ b/src/routes/users.ts @@ -12,5 +12,11 @@ export default async function users(fastify: FastifyInstance) { // get the user by provided id fastify.get<{ Params: UserParams - }>('/users/:id', async (req) => USERS.find(user => user.id === parseInt(req.params.id))) + }>('/users/:id', async (req, reply) => { + const user = USERS.find(user => user.id === parseInt(req.params.id)) + if(!user) { + reply.code(404).type('text/html').send('Not Found') + } + return user + }) }