From ddcf71225226bc0929d5c6d609b13ff0489e5b94 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 14 Aug 2021 22:28:17 +0200 Subject: Revamped backend error handling & improved imports in tests --- packages/server/src/routes/api/v1/repo/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'packages/server/src/routes/api/v1/repo/index.ts') diff --git a/packages/server/src/routes/api/v1/repo/index.ts b/packages/server/src/routes/api/v1/repo/index.ts index bcd2e5c..059a9d4 100644 --- a/packages/server/src/routes/api/v1/repo/index.ts +++ b/packages/server/src/routes/api/v1/repo/index.ts @@ -8,7 +8,7 @@ import branches from "./branches"; import log from "./log"; import { verifyRepoName } from "../../util"; import { Tree as APITree, Tag as APITag, TreeEntry as APITreeEntry } from "api"; -import { BaseError } from "../../../../git/error"; +import { ServerError } from "../../../../git/error"; import { commitMap } from "./map"; declare module "fastify" { @@ -19,9 +19,9 @@ declare module "fastify" { function addHooks(fastify: FastifyInstance, opts: FastifyPluginOptions): void { fastify.addHook("preHandler", async(req: CoolFastifyRequest, reply) => { - const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo, req.query.branch).catch((err: BaseError) => err); + const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo, req.query.branch).catch((err: ServerError) => err); - if(repository instanceof BaseError) { + if(repository instanceof ServerError) { reply.code(repository.code).send({ error: repository.message }); return; } @@ -67,9 +67,9 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do method: "GET", url: "/tree", handler: async(req, reply) => { - const tree = await req.repository.tree().catch((err: BaseError) => err); + const tree = await req.repository.tree().catch((err: ServerError) => err); - if(tree instanceof BaseError) { + if(tree instanceof ServerError) { reply.code(tree.code).send({ error: tree.message }); return; } @@ -81,9 +81,9 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do let data: APITree; if(tree_path) { - const tree_path_entry = await tree.find(tree_path).catch((err: BaseError) => err); + const tree_path_entry = await tree.find(tree_path).catch((err: ServerError) => err); - if(tree_path_entry instanceof BaseError) { + if(tree_path_entry instanceof ServerError) { reply.code(tree_path_entry.code).send({ error: tree_path_entry.message }); return; } @@ -104,9 +104,9 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do method: "GET", url: "/tree/history", handler: async(req, reply) => { - const tree = await req.repository.tree().catch((err: BaseError) => err); + const tree = await req.repository.tree().catch((err: ServerError) => err); - if(tree instanceof BaseError) { + if(tree instanceof ServerError) { reply.code(tree.code).send({ error: tree.message }); return; } @@ -118,9 +118,9 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do const tree_path = req.query.path; - const tree_entry = await tree.find(tree_path).catch((err: BaseError) => err); + const tree_entry = await tree.find(tree_path).catch((err: ServerError) => err); - if(tree_entry instanceof BaseError) { + if(tree_entry instanceof ServerError) { reply.code(tree_entry.code).send({ error: tree_entry.message }); return; } -- cgit v1.2.3-18-g5258