Skip to content

Commit

Permalink
Add error message parameter to onError callback in subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
cromoteca committed Dec 10, 2024
1 parent dfc0bca commit 2ff8fe1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ts/frontend/src/Connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface Subscription<T> {
onComplete(callback: () => void): Subscription<T>;

/** Called when an exception occured in the subscription. */
onError(callback: () => void): Subscription<T>;
onError(callback: (message: string) => void): Subscription<T>;

/** Called when a new value is available. */
onNext(callback: (value: T) => void): Subscription<T>;
Expand Down
6 changes: 3 additions & 3 deletions packages/ts/frontend/src/FluxConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class FluxConnection extends EventTarget {
readonly #endpointInfos = new Map<string, EndpointInfo>();
#nextId = 0;
readonly #onCompleteCallbacks = new Map<string, () => void>();
readonly #onErrorCallbacks = new Map<string, () => void>();
readonly #onErrorCallbacks = new Map<string, (message: string) => void>();
readonly #onNextCallbacks = new Map<string, (value: any) => void>();
readonly #onStateChangeCallbacks = new Map<string, (event: FluxSubscriptionStateChangeEvent) => void>();
readonly #statusOfSubscriptions = new Map<string, FluxSubscriptionState>();
Expand Down Expand Up @@ -154,7 +154,7 @@ export class FluxConnection extends EventTarget {
this.#onCompleteCallbacks.set(id, callback);
return hillaSubscription;
},
onError: (callback: () => void): Subscription<any> => {
onError: (callback: (message: string) => void): Subscription<any> => {
this.#onErrorCallbacks.set(id, callback);
return hillaSubscription;
},
Expand Down Expand Up @@ -285,7 +285,7 @@ export class FluxConnection extends EventTarget {
} else {
const callback = this.#onErrorCallbacks.get(id);
if (callback) {
callback();
callback(message.message);
}
this.#removeSubscription(id);
if (!callback) {
Expand Down
1 change: 1 addition & 0 deletions packages/ts/frontend/test/FluxConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('@vaadin/hilla-frontend', () => {
const msg: ClientErrorMessage = { '@type': 'error', id: '0', message: 'it failed' };
emitMessage(msg);
expect(onError).to.have.been.calledOnce;
expect(onError).to.have.been.calledWith('it failed');
});

it('should not deliver messages after completing', () => {
Expand Down

0 comments on commit 2ff8fe1

Please sign in to comment.