aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/utils/handlers.ts
blob: edd9a6c0cff978739fe0358a52027b429b03b368 (plain)
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
31
32
33
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import type { AxiosError } from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'

import logger from '../logger.ts'

/**
 * @param error the error
 * @param message the message to display
 */
export function handleError(error: AxiosError, message: string) {
	let fullMessage = ''

	if (message) {
		fullMessage += message
	}

	if (error.response?.status === 429) {
		if (fullMessage) {
			fullMessage += '\n'
		}
		fullMessage += t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.')
	}

	fullMessage = fullMessage || t('settings', 'Error')
	showError(fullMessage)
	logger.error(fullMessage, { error })
}