Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] [stable29] fix(files): handle empty view with error #48956

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/files/src/utils/davUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,37 @@ export function humanizeWebDAVError(error: unknown) {

return t('files', 'Unknown error')
}

/**
* 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')
}
Loading