From dfd299d4697a629f09ef20fc05c6d9e474bd5475 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 15 Aug 2021 15:29:53 +0200 Subject: Improved route parameter validation --- packages/server/src/routes/api/v1/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'packages/server/src/routes/api/v1/index.ts') diff --git a/packages/server/src/routes/api/v1/index.ts b/packages/server/src/routes/api/v1/index.ts index fb9cd8a..4b63435 100644 --- a/packages/server/src/routes/api/v1/index.ts +++ b/packages/server/src/routes/api/v1/index.ts @@ -8,13 +8,13 @@ import { ServerError } from "../../../git/error"; function setHandlers(fastify: FastifyInstance): void { fastify.setErrorHandler((err, req, reply) => { - console.log(err); - if(err.validation) { reply.code(400).send({ error: `${err.validation[0].dataPath} ${err.validation[0].message}` }); return; } + console.log(err); + reply.code(500).send({ error: "Internal server error!" }); }); fastify.setNotFoundHandler((req, reply) => { @@ -49,6 +49,11 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do fastify.route({ method: "GET", url: "/repos/:repo", + schema: { + params: { + repo: { type: "string" } + } + }, handler: async(req, reply) => { if(!verifyRepoName(req.params.repo)) { reply.code(400).send({ error: "Bad request" }); -- cgit v1.2.3-18-g5258