Skip to content

Commit c7c7e10

Browse files
Merge pull request #58670 from nextcloud/backport/58669/stable31
[stable31] fix(files_sharing): ensure the server share API errors are shown
2 parents f540b1a + f410e3d commit c7c7e10

14 files changed

Lines changed: 49 additions & 61 deletions

apps/files_sharing/src/mixins/ShareRequests.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
// TODO: remove when ie not supported
7-
import 'url-search-params-polyfill'
8-
9-
import { emit } from '@nextcloud/event-bus'
6+
import axios, { isAxiosError } from '@nextcloud/axios'
107
import { showError } from '@nextcloud/dialogs'
8+
import { emit } from '@nextcloud/event-bus'
119
import { generateOcsUrl } from '@nextcloud/router'
12-
import axios from '@nextcloud/axios'
13-
1410
import Share from '../models/Share.ts'
11+
import logger from '../services/logger.ts'
1512

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

@@ -45,13 +42,9 @@ export default {
4542
emit('files_sharing:share:created', { share })
4643
return share
4744
} catch (error) {
48-
console.error('Error while creating share', error)
49-
const errorMessage = error?.response?.data?.ocs?.meta?.message
50-
showError(
51-
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
52-
{ type: 'error' },
53-
)
54-
throw error
45+
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error creating the share')
46+
showError(errorMessage)
47+
throw new Error(errorMessage, { cause: error })
5548
}
5649
},
5750

@@ -70,13 +63,9 @@ export default {
7063
emit('files_sharing:share:deleted', { id })
7164
return true
7265
} catch (error) {
73-
console.error('Error while deleting share', error)
74-
const errorMessage = error?.response?.data?.ocs?.meta?.message
75-
OC.Notification.showTemporary(
76-
errorMessage ? t('files_sharing', 'Error deleting the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error deleting the share'),
77-
{ type: 'error' },
78-
)
79-
throw error
66+
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error deleting the share')
67+
showError(errorMessage)
68+
throw new Error(errorMessage, { cause: error })
8069
}
8170
},
8271

@@ -96,17 +85,27 @@ export default {
9685
return request.data.ocs.data
9786
}
9887
} catch (error) {
99-
console.error('Error while updating share', error)
100-
if (error.response.status !== 400) {
101-
const errorMessage = error?.response?.data?.ocs?.meta?.message
102-
OC.Notification.showTemporary(
103-
errorMessage ? t('files_sharing', 'Error updating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error updating the share'),
104-
{ type: 'error' },
105-
)
106-
}
107-
const message = error.response.data.ocs.meta.message
108-
throw new Error(message)
88+
logger.error('Error while updating share', { error })
89+
const errorMessage = getErrorMessage(error) ?? t('files_sharing', 'Error updating the share')
90+
// the error will be shown in apps/files_sharing/src/mixins/SharesMixin.js
91+
throw new Error(errorMessage, { cause: error })
10992
}
11093
},
11194
},
11295
}
96+
97+
/**
98+
* Handle an error response from the server and show a notification with the error message if possible
99+
*
100+
* @param {unknown} error - The received error
101+
* @return {string|undefined} the error message if it could be extracted from the response, otherwise undefined
102+
*/
103+
function getErrorMessage(error) {
104+
if (isAxiosError(error) && error.response.data?.ocs) {
105+
/** @type {import('@nextcloud/typings/ocs').OCSResponse} */
106+
const response = error.response.data
107+
if (response.ocs.meta?.message) {
108+
return response.ocs.meta.message
109+
}
110+
}
111+
}

dist/4185-4185.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/4185-4185.js.license

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
2424
SPDX-FileCopyrightText: Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)
2525
SPDX-FileCopyrightText: Matt Zabriskie
2626
SPDX-FileCopyrightText: Jonas Schade <derzade@gmail.com>
27-
SPDX-FileCopyrightText: Jerry Bendy <jerry@icewingcc.com>
2827
SPDX-FileCopyrightText: Jeff Sagal <sagalbot@gmail.com>
2928
SPDX-FileCopyrightText: James Halliday
3029
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
@@ -238,9 +237,6 @@ This file is generated from multiple sources. Included packages:
238237
- unist-util-visit
239238
- version: 5.1.0
240239
- license: MIT
241-
- url-search-params-polyfill
242-
- version: 8.2.5
243-
- license: MIT
244240
- util-deprecate
245241
- version: 1.0.2
246242
- license: MIT

dist/4185-4185.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-login.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-login.js.license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ This file is generated from multiple sources. Included packages:
193193
- version: 1.1.2
194194
- license: MIT
195195
- underscore
196-
- version: 1.13.7
196+
- version: 1.13.8
197197
- license: MIT
198198
- vue-loader
199199
- version: 15.11.1

dist/core-login.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-main.js.license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ This file is generated from multiple sources. Included packages:
238238
- version: 1.1.2
239239
- license: MIT
240240
- underscore
241-
- version: 1.13.7
241+
- version: 1.13.8
242242
- license: MIT
243243
- unist-builder
244244
- version: 4.0.0

dist/core-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)