-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapiError.ts
More file actions
30 lines (25 loc) · 979 Bytes
/
apiError.ts
File metadata and controls
30 lines (25 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*!
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/
import { isAxiosError } from '@nextcloud/axios'
import { logger } from './utils/logger.ts'
const [NC_MAJOR_VERSION] = window._oc_config?.version.split('.').map(Number) ?? []
/**
* Check if the given error is a confirmation error,
* which means that the password was incorrect.
*
* @param error - The error to check
*/
export function isConfirmationError(error: unknown): boolean {
if (!isAxiosError(error) || !error.response) {
return false
}
const hasConfirmationHeader = error.response.headers?.['x-nextcloud-password-confirmation'] === 'true'
if (NC_MAJOR_VERSION < 32) {
logger.debug('Handle legacy confirmation error based on status code', { status: error.response.status })
return error.response.status === 403
}
logger.debug('Handle modern confirmation error based on header', { hasConfirmationHeader })
return hasConfirmationHeader
}