Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 26 additions & 27 deletions apps/files_sharing/src/mixins/ShareRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import axios from '@nextcloud/axios'
import axios, { isAxiosError } from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { generateOcsUrl } from '@nextcloud/router'
import Share from '../models/Share.ts'
import logger from '../services/logger.ts'

// TODO: remove when ie not supported
import 'url-search-params-polyfill'

const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')

export default {
Expand Down Expand Up @@ -45,13 +42,9 @@ export default {
emit('files_sharing:share:created', { share })
return share
} catch (error) {
logger.error('Error while creating share', { error })
const errorMessage = error?.response?.data?.ocs?.meta?.message
showError(
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
{ type: 'error' },
)
throw error
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error creating the share')
showError(errorMessage)
throw new Error(errorMessage, { cause: error })
}
},

Expand All @@ -70,13 +63,9 @@ export default {
emit('files_sharing:share:deleted', { id })
return true
} catch (error) {
logger.error('Error while deleting share', { error })
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error deleting the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error deleting the share'),
{ type: 'error' },
)
throw error
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error deleting the share')
showError(errorMessage)
throw new Error(errorMessage, { cause: error })
}
},

Expand All @@ -97,16 +86,26 @@ export default {
}
} catch (error) {
logger.error('Error while updating share', { error })
if (error.response.status !== 400) {
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error updating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error updating the share'),
{ type: 'error' },
)
}
const message = error.response.data.ocs.meta.message
throw new Error(message)
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error updating the share')
// the error will be shown in apps/files_sharing/src/mixins/SharesMixin.js
throw new Error(errorMessage, { cause: error })
}
},
},
}

/**
* Handle an error response from the server and show a notification with the error message if possible
*
* @param {unknown} error - The received error
* @return {string|undefined} the error message if it could be extracted from the response, otherwise undefined
*/
function getErrorMessage(error) {
if (isAxiosError(error) && error.response.data?.ocs) {
/** @type {import('@nextcloud/typings/ocs').OCSResponse} */
const response = error.response.data
if (response.ocs.meta?.message) {
return response.ocs.meta.message
}
}
}
7 changes: 0 additions & 7 deletions build/frontend-legacy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion build/frontend-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"strengthify": "github:nextcloud/strengthify#0.5.9",
"throttle-debounce": "^5.0.2",
"underscore": "1.13.7",
"url-search-params-polyfill": "^8.2.5",
"v-click-outside": "^3.2.0",
"v-tooltip": "^2.1.3",
"vue": "^2.7.16",
Expand Down
4 changes: 2 additions & 2 deletions dist/8577-8577.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions dist/8577-8577.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Jonas Schade <derzade@gmail.com>
SPDX-FileCopyrightText: Jerry Bendy <jerry@icewingcc.com>
SPDX-FileCopyrightText: Jeff Sagal <sagalbot@gmail.com>
SPDX-FileCopyrightText: James Halliday
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
Expand Down Expand Up @@ -275,9 +274,6 @@ This file is generated from multiple sources. Included packages:
- unist-util-visit
- version: 5.1.0
- license: MIT
- url-search-params-polyfill
- version: 8.2.5
- license: MIT
- util-deprecate
- version: 1.0.2
- license: MIT
Expand Down
2 changes: 1 addition & 1 deletion dist/8577-8577.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

Loading