Skip to content

Commit

Permalink
Merge pull request #1743 from Code-Hive-GmbH/master
Browse files Browse the repository at this point in the history
feat(): Improve query bus to throw error with query name
  • Loading branch information
kamilmysliwiec authored Oct 29, 2024
2 parents 0bd31ef + 38d2160 commit 0099dd1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/query-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class QueryBus<QueryBase extends IQuery = IQuery>
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);
Expand Down Expand Up @@ -120,4 +121,9 @@ export class QueryBus<QueryBase extends IQuery = IQuery>
private useDefaultPublisher() {
this._publisher = new DefaultQueryPubSub<QueryBase>(this.subject$);
}

private getQueryName(query: QueryBase): string {
const { constructor } = Object.getPrototypeOf(query);
return constructor.name as string;
}
}

0 comments on commit 0099dd1

Please sign in to comment.