Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error message parameter to onError callback in subscription #2987

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading