From ec4fcd3fc8843b86af832c343ff71e18b9100f47 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 8 Sep 2022 10:36:55 -0500 Subject: [PATCH] Improve error handling for Xero linking --- src/Xero.hs | 10 +++++++--- src/ZGoBackend.hs | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Xero.hs b/src/Xero.hs index 9fe39a6..3373409 100644 --- a/src/Xero.hs +++ b/src/Xero.hs @@ -356,9 +356,13 @@ getTenantId pipe dbName t = do setRequestMethod "GET" defaultRequest res <- httpJSON req let tenants = getResponseBody (res :: Response [XeroTenant]) - --print tenants - _ <- access pipe master dbName $ setTenant (t_address t) (head tenants) - return () + print tenants + if not (null tenants) + then do + _ <- + access pipe master dbName $ setTenant (t_address t) (head tenants) + return () + else error "Couldn't find tenant ID" _ -> error "Incorrect type for authorization_event_id" -- | Update an Owner with XeroTenant id diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 1a0928a..65e3128 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -548,7 +548,8 @@ routes pipe config = do Nothing -> status noContent204 Just c -> do res <- - liftIO $ requestXeroToken pipe (c_dbName config) c code address + liftAndCatchIO $ + requestXeroToken pipe (c_dbName config) c code address if res then status ok200 else status noContent204