Browse Source

refactor: reset config to initial state if retry mechanism failed

pull/9717/head
Pranav C 4 weeks ago
parent
commit
189f9a696f
  1. 17
      packages/nc-gui/components/workspace/integrations/forms/EditOrAddDatabase.vue

17
packages/nc-gui/components/workspace/integrations/forms/EditOrAddDatabase.vue

@ -307,22 +307,19 @@ const createOrUpdateIntegration = async () => {
function applyConfigFix(fix: any) { function applyConfigFix(fix: any) {
if (!fix) return if (!fix) return
formState.value = { formState.value.dataSource = {
...formState.value,
dataSource: {
...formState.value.dataSource, ...formState.value.dataSource,
...fix, ...fix,
connection: { connection: {
...formState.value.dataSource.connection, ...formState.value.dataSource.connection,
...fix.connection, ...fix.connection,
}, },
},
} }
} }
const testConnectionError = ref() const testConnectionError = ref()
const testConnection = async (retry = 0) => { const testConnection = async (retry = 0, initialConfig = null) => {
try { try {
await validate() await validate()
} catch (e) { } catch (e) {
@ -362,18 +359,22 @@ const testConnection = async (retry = 0) => {
} }
} }
} catch (e: any) { } catch (e: any) {
await handleConnectionError(e, retry) // take a copy of the current config
const config = initialConfig || JSON.parse(JSON.stringify(formState.value.dataSource))
await handleConnectionError(e, retry, config)
} finally { } finally {
testingConnection.value = false testingConnection.value = false
} }
} }
async function handleConnectionError(e: any, retry: number): Promise<void> { async function handleConnectionError(e: any, retry: number, initialConfig: any): Promise<void> {
const MAX_RETRIES = 3 const MAX_RETRIES = 3
if (retry >= MAX_RETRIES) { if (retry >= MAX_RETRIES) {
testSuccess.value = false testSuccess.value = false
testConnectionError.value = await extractSdkResponseErrorMsg(e) testConnectionError.value = await extractSdkResponseErrorMsg(e)
// reset the connection config to initial state
formState.value.dataSource = initialConfig
return return
} }
@ -382,7 +383,7 @@ async function handleConnectionError(e: any, retry: number): Promise<void> {
if (fix) { if (fix) {
applyConfigFix(fix) applyConfigFix(fix)
// Retry the connection after applying the fix // Retry the connection after applying the fix
return testConnection(retry + 1) return testConnection(retry + 1, initialConfig)
} }
// If no fix is available, or fix did not resolve the issue // If no fix is available, or fix did not resolve the issue

Loading…
Cancel
Save