Skip to content

Commit ac690ea

Browse files
committed
fix(user_ldap): Properly handle new wizard OCS endpoint error
Signed-off-by: Louis Chmn <[email protected]>
1 parent f57fb6e commit ac690ea

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

apps/user_ldap/src/services/ldapConfigService.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { AxiosResponse } from '@nextcloud/axios'
88
import type { OCSResponse } from '@nextcloud/typings/ocs'
99
import type { LDAPConfig } from '../models/index.ts'
1010

11-
import axios from '@nextcloud/axios'
11+
import axios, { isAxiosError } from '@nextcloud/axios'
1212
import { getDialogBuilder, showError, showSuccess } from '@nextcloud/dialogs'
1313
import { t } from '@nextcloud/l10n'
1414
import { generateOcsUrl } from '@nextcloud/router'
@@ -164,20 +164,23 @@ export async function callWizard(action: WizardAction, configId: string, extraPa
164164
params.set(key, value)
165165
})
166166

167-
const response = await axios.post(
168-
generateOcsUrl('apps/user_ldap/api/v1/wizard/{configId}/{action}', { configId, action }),
169-
params,
170-
) as AxiosResponse<OCSResponse<{ changes?: Record<string, unknown>, options?: Record<string, []> }>>
167+
try {
168+
const response = await axios.post(
169+
generateOcsUrl('apps/user_ldap/api/v1/wizard/{configId}/{action}', { configId, action }),
170+
params,
171+
) as AxiosResponse<OCSResponse<{ changes?: Record<string, unknown>, options?: Record<string, []> }>>
171172

172-
logger.debug(`Called wizard action: ${action}`, { configId, params, response })
173+
logger.debug(`Called wizard action: ${action}`, { configId, params, response })
173174

174-
if (response.data.ocs.meta.status === 'failure') {
175-
const message = response.data.ocs.meta.message ?? t('user_ldap', 'An error occurred')
176-
showError(message)
177-
throw new Error(message)
178-
}
175+
return response.data.ocs.data
176+
} catch (error) {
177+
if (isAxiosError(error) && error.response?.data.ocs.meta.status === 'failure') {
178+
const message = error.response.data.ocs.meta.message ?? t('user_ldap', 'An error occurred')
179+
showError(message)
180+
}
179181

180-
return response.data.ocs.data
182+
throw error
183+
}
181184
}
182185

183186
/**

0 commit comments

Comments
 (0)