mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-29 01:15:48 +02:00
ux: return better error message if a segment doesn't exist (#4122)
Catch cases where the segment doesn't exist and populate that error message with more info: it now says that a segment with <id> doesn't exist instead of just 'No row'.
This commit is contained in:
parent
3a14b97fdd
commit
4a4f14f69b
30
src/lib/db/segment-store.test.ts
Normal file
30
src/lib/db/segment-store.test.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { ISegmentStore } from '../types/stores/segment-store';
|
||||||
|
import dbInit from '../../test/e2e/helpers/database-init';
|
||||||
|
import getLogger from '../../test/fixtures/no-logger';
|
||||||
|
import NotFoundError from '../error/notfound-error';
|
||||||
|
|
||||||
|
let stores;
|
||||||
|
let db;
|
||||||
|
let segmentStore: ISegmentStore;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
db = await dbInit('segment_store_serial', getLogger);
|
||||||
|
stores = db.stores;
|
||||||
|
segmentStore = stores.segmentStore;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await db.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('unexpected input handling for get segment', () => {
|
||||||
|
test("gives a NotFoundError with the ID of the segment if it doesn't exist", async () => {
|
||||||
|
const id = 123;
|
||||||
|
try {
|
||||||
|
await segmentStore.get(id);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e instanceof NotFoundError).toBeTruthy();
|
||||||
|
expect(e.message).toEqual(expect.stringMatching(id.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -195,7 +195,12 @@ export default class SegmentStore implements ISegmentStore {
|
|||||||
.from(T.segments)
|
.from(T.segments)
|
||||||
.where({ id });
|
.where({ id });
|
||||||
|
|
||||||
return this.mapRow(rows[0]);
|
const row = rows[0];
|
||||||
|
if (!row) {
|
||||||
|
throw new NotFoundError(`No segment exists with ID "${id}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.mapRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addToStrategy(id: number, strategyId: string): Promise<void> {
|
async addToStrategy(id: number, strategyId: string): Promise<void> {
|
||||||
|
Loading…
Reference in New Issue
Block a user