mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02: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:
parent
77dd5d6c9f
commit
497ed6fed8
@ -6,6 +6,7 @@ import {
|
|||||||
IContextFieldStore,
|
IContextFieldStore,
|
||||||
ILegalValue,
|
ILegalValue,
|
||||||
} from '../types/stores/context-field-store';
|
} from '../types/stores/context-field-store';
|
||||||
|
import NotFoundError from '../error/notfound-error';
|
||||||
|
|
||||||
const COLUMNS = [
|
const COLUMNS = [
|
||||||
'name',
|
'name',
|
||||||
@ -76,11 +77,16 @@ class ContextFieldStore implements IContextFieldStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get(key: string): Promise<IContextField> {
|
async get(key: string): Promise<IContextField> {
|
||||||
return this.db
|
const row = await this.db
|
||||||
.first(COLUMNS)
|
.first(COLUMNS)
|
||||||
.from(TABLE)
|
.from(TABLE)
|
||||||
.where({ name: key })
|
.where({ name: key });
|
||||||
.then(mapRow);
|
if (!row) {
|
||||||
|
throw new NotFoundError(
|
||||||
|
`Could not find Context field with name ${key}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return mapRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteAll(): Promise<void> {
|
async deleteAll(): Promise<void> {
|
||||||
|
Loading…
Reference in New Issue
Block a user