aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/api/v1/index.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-21 22:00:04 +0200
committerHampusM <hampus@hampusmat.com>2021-07-21 22:00:04 +0200
commit7b9fca8d0061cf5e5af08cba98e9d5b6dbbed8ec (patch)
tree2a75dfaaa495c90e5519012e2c8e20ab0bd7ac4e /packages/server/src/api/v1/index.ts
parentc0eb6635964de276b44851df67fb857ae94dc401 (diff)
Began with better backend error handling & cleaned up the backend
Diffstat (limited to 'packages/server/src/api/v1/index.ts')
-rw-r--r--packages/server/src/api/v1/index.ts15
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/server/src/api/v1/index.ts b/packages/server/src/api/v1/index.ts
index c6b9187..169ba3a 100644
--- a/packages/server/src/api/v1/index.ts
+++ b/packages/server/src/api/v1/index.ts
@@ -4,6 +4,7 @@ import { Route } from "../../fastify_types";
import repo from "./repo";
import { verifyRepoName } from "../util";
import { Info as APIInfo, RepositorySummary as APIRepositorySummary, Repository as APIRepository } from "shared_types";
+import { BaseError } from "../../git/error";
function setHandlers(fastify: FastifyInstance): void {
fastify.setErrorHandler((err, req, reply) => {
@@ -32,7 +33,7 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do
return <APIRepositorySummary>{
name: repository.name.short,
description: repository.description,
- last_updated: (await repository.latestCommit()).date
+ last_updated: (await repository.masterCommit()).date
};
}))
});
@@ -43,13 +44,17 @@ function reposEndpoints(fastify: FastifyInstance, opts: FastifyPluginOptions, do
method: "GET",
url: "/repos/:repo",
handler: async(req, reply) => {
- const repo_verification = await verifyRepoName(opts.config.settings.base_dir, req.params.repo);
- if(repo_verification.success === false && repo_verification.code) {
- reply.code(repo_verification.code).send({ error: repo_verification.message });
+ if(!verifyRepoName(req.params.repo)) {
+ reply.code(400).send({ error: "Bad request" });
return;
}
- const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo);
+ const repository = await Repository.open(opts.config.settings.base_dir, req.params.repo).catch(err => err);
+
+ if(repository instanceof BaseError) {
+ reply.code(repository.code).send({ error: repository.message });
+ return;
+ }
const data: APIRepository = {
name: repository.name.short,