From 94007c04728805448ad79527cc888bc8df542162 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Wed, 6 Mar 2024 14:12:50 +0100 Subject: [PATCH] handle query exception, in particular when reloading page --- src/renderer/component/Debug.tsx | 6 +++++- src/sql/index.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/renderer/component/Debug.tsx b/src/renderer/component/Debug.tsx index 709918b..474caed 100644 --- a/src/renderer/component/Debug.tsx +++ b/src/renderer/component/Debug.tsx @@ -13,9 +13,13 @@ const Url = styled.div` padding: 2px 5px; `; -function Debug(): ReactElement { +function Debug(): ReactElement | null { const location = useLocation(); + if (process.env.NODE_ENV !== 'development') { + return null; + } + return ( {location.pathname} diff --git a/src/sql/index.ts b/src/sql/index.ts index ea7e497..73533bb 100644 --- a/src/sql/index.ts +++ b/src/sql/index.ts @@ -28,7 +28,18 @@ class ConnectionStack { log('SQL', `Execute query on "${connectionName}": "${query}"`); - return await connection.query(query); + try { + return await connection.query(query); + } catch (error) { + // retry once + log('SQL', `Error on "${connectionName}"`, error); + + this.connections.delete(connectionName); + + const renewedConnection = await this.#getConnection(connectionName); + + return await renewedConnection.query(query); + } } async closeAllConnections(): Promise {