From 3205965afbd9c4fce00dc03cccd6b6223ddb1d15 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Sun, 8 Dec 2019 14:17:23 -0500 Subject: Overhaul error handling for controllers This change fixes various issues with the GET endpoints to return more accurate error messages. It adds business logic error objects that are returned in a union type in the controllers. This change should help separate the business logic from the actual errors from upstream services. There may be required changes still with handling those upstream errors via Promises. Integration tests should be added to verify issues. --- src/metadata.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/metadata.ts') diff --git a/src/metadata.ts b/src/metadata.ts index c297b38..07e420d 100644 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -2,6 +2,7 @@ import { Db } from "mongodb"; import winston from "winston"; import logger_config from "./util/logger"; +import { BranchNotFoundError } from "./errors"; interface Branch { head: string; @@ -37,7 +38,7 @@ class Metadata { organization: string, repository: string, branch: string - ): Promise { + ): Promise { const result = await this.database .collection("repository") .findOne({ @@ -57,7 +58,7 @@ class Metadata { ); return limb.head; } else { - throw Error("Branch not found"); + return new BranchNotFoundError(); } } -- cgit