From 76582dd9f46f98cc22ea07696e6c2e6971bf5907 Mon Sep 17 00:00:00 2001 From: Aaron Maier Date: Sat, 13 Jul 2024 10:13:27 +0200 Subject: [PATCH 1/2] Show query name in error, instead of query uuid to make Exception messages more useful --- src/query-bus.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/query-bus.ts b/src/query-bus.ts index 39666bb3..e4ba9f3a 100644 --- a/src/query-bus.ts +++ b/src/query-bus.ts @@ -59,7 +59,8 @@ export class QueryBus const queryId = this.getQueryId(query); const handler = this.handlers.get(queryId); if (!handler) { - throw new QueryHandlerNotFoundException(queryId); + const queryName = this.getQueryName(query); + throw new QueryHandlerNotFoundException(queryName); } this._publisher.publish(query); @@ -120,4 +121,9 @@ export class QueryBus private useDefaultPublisher() { this._publisher = new DefaultQueryPubSub(this.subject$); } + + private getQueryName(query: Type): string { + const { constructor } = Object.getPrototypeOf(query); + return constructor.name; + } } From 38d21606da843926273403a63f408444c4fc30af Mon Sep 17 00:00:00 2001 From: Aaron Maier Date: Thu, 8 Aug 2024 13:12:55 +0200 Subject: [PATCH 2/2] Fix typing for getQueryName function --- src/query-bus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/query-bus.ts b/src/query-bus.ts index e4ba9f3a..dd7890e7 100644 --- a/src/query-bus.ts +++ b/src/query-bus.ts @@ -122,8 +122,8 @@ export class QueryBus this._publisher = new DefaultQueryPubSub(this.subject$); } - private getQueryName(query: Type): string { + private getQueryName(query: QueryBase): string { const { constructor } = Object.getPrototypeOf(query); - return constructor.name; + return constructor.name as string; } }