Skip to content

Commit

Permalink
fix: correct error for missing context field (#3647)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Christopher Kolstad committed Apr 28, 2023
1 parent a984de7 commit f1db90d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/db/context-field-store.ts
Expand Up @@ -6,6 +6,7 @@ import {
IContextFieldStore,
ILegalValue,
} from '../types/stores/context-field-store';
import NotFoundError from '../error/notfound-error';

const COLUMNS = [
'name',
Expand Down Expand Up @@ -76,11 +77,16 @@ class ContextFieldStore implements IContextFieldStore {
}

async get(key: string): Promise<IContextField> {
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<void> {
Expand Down

0 comments on commit f1db90d

Please sign in to comment.