aboutsummaryrefslogtreecommitdiff
path: root/src/formats.ts
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2019-12-08 14:17:23 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2019-12-08 14:17:23 -0500
commit3205965afbd9c4fce00dc03cccd6b6223ddb1d15 (patch)
tree1c938e39ae5e6ca6d9fca87965b405a30aa8d0f1 /src/formats.ts
parentad627b0c6ba9bc804ed2924c692c8ef7e022fca6 (diff)
downloadao-coverage-3205965afbd9c4fce00dc03cccd6b6223ddb1d15.tar.gz
ao-coverage-3205965afbd9c4fce00dc03cccd6b6223ddb1d15.tar.bz2
ao-coverage-3205965afbd9c4fce00dc03cccd6b6223ddb1d15.zip
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.
Diffstat (limited to 'src/formats.ts')
-rw-r--r--src/formats.ts6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/formats.ts b/src/formats.ts
index 59a966e..1b5a572 100644
--- a/src/formats.ts
+++ b/src/formats.ts
@@ -1,6 +1,8 @@
+import { InvalidReportDocumentError } from "./errors";
+
export interface Format {
// returns the coverage value as %: Number(90.0), Number(100.0), Number(89.5)
- parse_coverage: (file: Document) => number;
+ parse_coverage: (file: Document) => number | InvalidReportDocumentError;
match_color: (coverage: number, stage_1: number, stage_2: number) => string;
}
@@ -35,7 +37,7 @@ const FormatsObj: FormatObj = {
parse_coverage: (file: Document) => {
const scripts = file.getElementsByTagName("script");
if (scripts.length == 0) {
- throw new Error("Invalid report document");
+ return new InvalidReportDocumentError();
}
const data = scripts[0].text;
const accumFunc = (regex: RegExp) => {