Skip to content

Commit

Permalink
handle query exception, in particular when reloading page
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Mar 6, 2024
1 parent b92642f commit 94007c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/renderer/component/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<DebugContainer>
<Url>{location.pathname}</Url>
Expand Down
13 changes: 12 additions & 1 deletion src/sql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down

0 comments on commit 94007c0

Please sign in to comment.