aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/routes/api
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-08-14 22:28:17 +0200
committerHampusM <hampus@hampusmat.com>2021-08-14 22:28:17 +0200
commitddcf71225226bc0929d5c6d609b13ff0489e5b94 (patch)
tree7f788d29af4441e27d709aaec1359e205871a11b /packages/server/src/routes/api
parent81b39ee7848b0fbdcd8b61a04077a58c23580dd1 (diff)
Revamped backend error handling & improved imports in tests
Diffstat (limited to 'packages/server/src/routes/api')
-rw-r--r--packages/server/src/routes/api/v1/index.ts6
-rw-r--r--packages/server/src/routes/api/v1/repo/index.ts22
2 files changed, 14 insertions, 14 deletions
diff --git a/packages/server/src/routes/api/v1/index.ts b/packages/server/src/routes/api/v1/index.ts
index 1adb3cb..fa7d8ab 100644
--- a/packages/server/src/routes/api/v1/index.ts
+++ b/packages/server/src/routes/api/v1/index.ts
@@ -4,7 +4,7 @@ import { Route } from "../../../types/fastify";
import repo from "./repo";
import { verifyRepoName } from "../util";
import { Info as APIInfo, RepositorySummary as APIRepositorySummary, Repository as APIRepository } from "api";
-import { BaseError } from "../../../git/error";
+import { ServerError } from "../../../git/error";
function setHandlers(fastify: FastifyInstance): void {
fastify.setErrorHandler((err, req, reply) => {
@@ -49,9 +49,9 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do
return;
}
- const repository: Repository | BaseError = await Repository.open(opts.config.settings.git_dir, req.params.repo).catch(err => err);
+ const repository = await Repository.open(opts.config.settings.git_dir, req.params.repo).catch((err: ServerError) => err);
- if(repository instanceof BaseError) {
+ if(repository instanceof ServerError) {
reply.code(repository.code).send({ error: repository.message });
return;
}
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;
}