From d67fb1f8f2b1533afd40e387728dc96842eb9180 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Tue, 19 Jul 2022 09:33:14 +0200 Subject: [PATCH] Improved error message when DeleteDataSubscription fails because the DataSubscription doesn't exists --- IHP/DataSync/ControllerImpl.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/IHP/DataSync/ControllerImpl.hs b/IHP/DataSync/ControllerImpl.hs index 17e26b082..568dd345d 100644 --- a/IHP/DataSync/ControllerImpl.hs +++ b/IHP/DataSync/ControllerImpl.hs @@ -144,14 +144,15 @@ runDataSyncController ensureRLSEnabled installTableChangeTriggers receiveData se handleMessage DeleteDataSubscription { requestId, subscriptionId } = do DataSyncReady { subscriptions } <- getState - let (Just closeSignalMVar) = HashMap.lookup subscriptionId subscriptions - - -- Cancel table watcher - MVar.putMVar closeSignalMVar () + case HashMap.lookup subscriptionId subscriptions of + Just closeSignalMVar -> do + -- Cancel table watcher + MVar.putMVar closeSignalMVar () - modifyIORef' ?state (\state -> state |> modify #subscriptions (HashMap.delete subscriptionId)) + modifyIORef' ?state (\state -> state |> modify #subscriptions (HashMap.delete subscriptionId)) - sendJSON DidDeleteDataSubscription { subscriptionId, requestId } + sendJSON DidDeleteDataSubscription { subscriptionId, requestId } + Nothing -> error ("Failed to delete DataSubscription, could not find DataSubscription with id " <> tshow subscriptionId) handleMessage CreateRecordMessage { table, record, requestId, transactionId } = do ensureRLSEnabled table