1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

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.
This commit is contained in:
Christopher Kolstad 2023-04-28 11:21:32 +02:00 committed by GitHub
parent a984de7941
commit f1db90d38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<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> {