diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-15 15:29:53 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-15 15:29:53 +0200 |
commit | dfd299d4697a629f09ef20fc05c6d9e474bd5475 (patch) | |
tree | 5b47b64afc379101187acec7c0f95baf7b1dba04 /packages/server/src/routes/api/v1/index.ts | |
parent | 9736749a779661a95211a91200617a03a1b9a702 (diff) |
Improved route parameter validation
Diffstat (limited to 'packages/server/src/routes/api/v1/index.ts')
-rw-r--r-- | packages/server/src/routes/api/v1/index.ts | 9 |
1 files changed, 7 insertions, 2 deletions
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<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" }); |