From d7dc326654f1bf26503009a21e7223894f367fa1 Mon Sep 17 00:00:00 2001 From: Vice Phenek Date: Tue, 27 Sep 2022 12:05:41 +0200 Subject: [PATCH] - SetError on connection errors --- src/useHub.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/useHub.ts b/src/useHub.ts index 0790aa6..6a9f8ba 100644 --- a/src/useHub.ts +++ b/src/useHub.ts @@ -29,9 +29,15 @@ export function useHub(hubConnection?: HubConnection) { setHubConnectionState(hubConnection?.state); } } - hubConnection.onclose(onStateUpdatedCallback); + + const onConnectErrorCallback = (error?: Error | undefined) => { + onStateUpdatedCallback(); + setError(error?.message); + } + + hubConnection.onclose(onConnectErrorCallback); hubConnection.onreconnected(onStateUpdatedCallback); - hubConnection.onreconnecting(onStateUpdatedCallback); + hubConnection.onreconnecting(onConnectErrorCallback); if (hubConnection.state === HubConnectionState.Disconnected) { const startPromise = hubConnection