-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48934 from nextcloud/backport/48625/stable29
- Loading branch information
Showing
19 changed files
with
103 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { t } from '@nextcloud/l10n' | ||
import type { WebDAVClientError } from 'webdav' | ||
|
||
/** | ||
* Whether error is a WebDAVClientError | ||
* @param error - Any exception | ||
* @return {boolean} - Whether error is a WebDAVClientError | ||
*/ | ||
function isWebDAVClientError(error: unknown): error is WebDAVClientError { | ||
return error instanceof Error && 'status' in error && 'response' in error | ||
} | ||
|
||
/** | ||
* Get a localized error message from webdav request | ||
* @param error - An exception from webdav request | ||
* @return {string} Localized error message for end user | ||
*/ | ||
export function humanizeWebDAVError(error: unknown) { | ||
if (error instanceof Error) { | ||
if (isWebDAVClientError(error)) { | ||
const status = error.status || error.response?.status || 0 | ||
if ([400, 404, 405].includes(status)) { | ||
return t('files', 'Folder not found') | ||
} else if (status === 403) { | ||
return t('files', 'This operation is forbidden') | ||
} else if (status === 500) { | ||
return t('files', 'This directory is unavailable, please check the logs or contact the administrator') | ||
} else if (status === 503) { | ||
return t('files', 'Storage is temporarily not available') | ||
} | ||
} | ||
return t('files', 'Unexpected error: {error}', { error: error.message }) | ||
} | ||
|
||
return t('files', 'Unknown error') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.