From f1db90d38cc031d1612bf901c7864baaef0897e0 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Fri, 28 Apr 2023 11:21:32 +0200 Subject: [PATCH] fix: correct error for missing context field (#3647) When adding a strategy using a context field that did not exist, we threw an unknown error. This changes to throw NotFoundError so that our users can better know what they did wrong. --- src/lib/db/context-field-store.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/db/context-field-store.ts b/src/lib/db/context-field-store.ts index 5efe42ccaa..92b620d782 100644 --- a/src/lib/db/context-field-store.ts +++ b/src/lib/db/context-field-store.ts @@ -6,6 +6,7 @@ import { IContextFieldStore, ILegalValue, } from '../types/stores/context-field-store'; +import NotFoundError from '../error/notfound-error'; const COLUMNS = [ 'name', @@ -76,11 +77,16 @@ class ContextFieldStore implements IContextFieldStore { } async get(key: string): Promise { - return this.db + const row = await this.db .first(COLUMNS) .from(TABLE) - .where({ name: key }) - .then(mapRow); + .where({ name: key }); + if (!row) { + throw new NotFoundError( + `Could not find Context field with name ${key}`, + ); + } + return mapRow(row); } async deleteAll(): Promise {