diff --git a/plugins/events-backend/src/service/EventsPlugin.test.ts b/plugins/events-backend/src/service/EventsPlugin.test.ts index 215d4e9190..53f84ffed1 100644 --- a/plugins/events-backend/src/service/EventsPlugin.test.ts +++ b/plugins/events-backend/src/service/EventsPlugin.test.ts @@ -416,5 +416,19 @@ describe('eventsPlugin', () => { await backend.stop(); }, ); + + it.each(databases.eachSupportedId())( + 'should refuse listen without a subscription, %p', + async databaseId => { + const backend = await startTestBackend({ + features: [eventsPlugin(), await mockKnexFactory(databaseId)], + }); + const helper = new ReqHelper(backend); + + await helper.readEvents('nonexistent').expect(404); + + await backend.stop(); + }, + ); }); }); diff --git a/plugins/events-backend/src/service/hub/MemoryEventBusStore.ts b/plugins/events-backend/src/service/hub/MemoryEventBusStore.ts index 629c341a76..3071a51edf 100644 --- a/plugins/events-backend/src/service/hub/MemoryEventBusStore.ts +++ b/plugins/events-backend/src/service/hub/MemoryEventBusStore.ts @@ -15,6 +15,7 @@ */ import { EventParams } from '@backstage/plugin-events-node'; import { EventBusStore } from './types'; +import { NotFoundError } from '@backstage/errors'; const MAX_BATCH_SIZE = 10; @@ -80,7 +81,7 @@ export class MemoryEventBusStore implements EventBusStore { async readSubscription(id: string): Promise<{ events: EventParams[] }> { const sub = this.#subscribers.get(id); if (!sub) { - throw new Error(`Subscription not found`); + throw new NotFoundError(`Subscription not found`); } const events = this.#events .filter( @@ -108,7 +109,7 @@ export class MemoryEventBusStore implements EventBusStore { const sub = this.#subscribers.get(subscriptionId); if (!sub) { - throw new Error(`Subscription not found`); + throw new NotFoundError(`Subscription not found`); } return new Promise<{ topic: string }>((resolve, reject) => {