Skip to content

Commit

Permalink
Enable error log for ocs and webdav requests (#9482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Aug 2, 2023
1 parent 71641e0 commit bce11d2
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 66 deletions.
11 changes: 11 additions & 0 deletions changelog/enhancement-error-notifications-include-x-request-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Enhancement: Error notifications include x-request-id

We've added a details box for the notifications, that pop up if an operation (e.g upload, download, add a share) fails.
This box contains the x-request-id and may help to debug the error on the server side.

https://github.com/owncloud/web/pull/9482
https://github.com/owncloud/web/pull/9474
https://github.com/owncloud/web/pull/9466
https://github.com/owncloud/web/pull/9448
https://github.com/owncloud/web/pull/9426
https://github.com/owncloud/web/issues/9449
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@
><oc-icon name="close"
/></oc-button>
</div>
<div class="oc-width-1-1">
<div class="oc-flex oc-flex-between oc-width-1-1 oc-mt-s">
<span
v-if="message"
class="oc-notification-message-content oc-text-muted oc-mr-s"
v-text="message"
/>
<oc-button
v-if="errorLogContent"
class="oc-notification-message-error-log-toggle-button"
gap-size="none"
appearance="raw"
@click="showErrorLog = !showErrorLog"
>
<span v-text="$gettext('Details')"></span>
<oc-icon :name="showErrorLog ? 'arrow-up-s' : 'arrow-down-s'" />
</oc-button>
</div>
<oc-error-log v-if="showErrorLog" class="oc-mt-m" :content="errorLogContent" />
<div v-if="message || errorLogContent" class="oc-flex oc-flex-between oc-width-1-1 oc-mt-s">
<span
v-if="message"
class="oc-notification-message-content oc-text-muted oc-mr-s"
v-text="message"
/>
<oc-button
v-if="errorLogContent"
class="oc-notification-message-error-log-toggle-button"
gap-size="none"
appearance="raw"
@click="showErrorLog = !showErrorLog"
>
<span v-text="$gettext('Details')"></span>
<oc-icon :name="showErrorLog ? 'arrow-up-s' : 'arrow-down-s'" />
</oc-button>
</div>
<oc-error-log v-if="showErrorLog" class="oc-mt-m" :content="errorLogContent" />
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ export default defineComponent({
}
errors.forEach((e) => {
this.showErrorMessage({
title: this.$gettext('Failed to add share for %{displayName}', {
title: this.$gettext('Failed to add share for "%{displayName}"', {
displayName: e.displayName
}),
error: e
error: e.error
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const useFileActionsRestore = ({ store }: { store?: Store<any> } = {}) =>
) => {
const restoredResources = []
const failedResources = []
const errors = []

let createdFolderPaths = []
for (const [i, resource] of resources.entries()) {
Expand All @@ -174,6 +175,7 @@ export const useFileActionsRestore = ({ store }: { store?: Store<any> } = {}) =>
restoredResources.push(resource)
} catch (e) {
console.error(e)
errors.push(e)
failedResources.push(resource)
} finally {
setProgress({ total: resources.length, current: i + 1 })
Expand Down Expand Up @@ -209,7 +211,8 @@ export const useFileActionsRestore = ({ store }: { store?: Store<any> } = {}) =>
translateParams.resourceCount = failedResources.length
}
store.dispatch('showErrorMessage', {
title: $gettextInterpolate(translated, translateParams, true)
title: $gettextInterpolate(translated, translateParams, true),
errors
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class ResourceTransfer extends ConflictDialog {
)
}
this.showErrorMessage({
title
title,
errors
})
}

Expand Down
33 changes: 20 additions & 13 deletions packages/web-app-files/src/helpers/share/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,26 @@ export const createQuicklink = async (args: CreateQuicklink): Promise<Share> =>

params.spaceRef = resource.fileId || resource.id

const link = await store.dispatch('Files/addLink', {
path: resource.path,
client: clientService.owncloudSdk,
params,
storageId: resource.fileId || resource.id
})
try {
const link = await store.dispatch('Files/addLink', {
path: resource.path,
client: clientService.owncloudSdk,
params,
storageId: resource.fileId || resource.id
})
const { copy } = useClipboard({ legacy: true })
copy(link.url)

const { copy } = useClipboard({ legacy: true })
copy(link.url)
await store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})

await store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})

return link
return link
} catch (e) {
console.error(e)
await store.dispatch('showErrorMessage', {
title: $gettext('Copy link failed'),
error: e
})
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { aggregateResourceShares } from '../resources'
import { ShareStatus } from 'web-client/src/helpers/share/status'
import { HttpError } from 'web-pkg/src/errors'

export async function triggerShareAction(resource, status, hasReSharing, hasShareJail, $client) {
const method = _getRequestMethod(status)
Expand All @@ -16,7 +17,7 @@ export async function triggerShareAction(resource, status, hasReSharing, hasShar

// exit on failure
if (response.status !== 200) {
throw new Error(response.statusText)
throw new HttpError(response.statusText, response)
}

// get updated share from response and transform & return it
Expand Down
22 changes: 8 additions & 14 deletions packages/web-pkg/src/composables/download/useDownloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { unref } from 'vue'
import { usePublicLinkContext } from '../authContext'
import { useClientService } from '../clientService'
import { useStore } from '../store'
import { v4 as uuidV4 } from 'uuid'
import { triggerDownloadWithFilename } from 'web-pkg/src/helpers'
import { useGettext } from 'vue3-gettext'
import { useCapabilityCoreSupportUrlSigning } from '../capability'
Expand All @@ -19,8 +18,7 @@ export const useDownloadFile = () => {
const isUserContext = store.getters['runtime/auth/isUserContextReady']

// construct the url and headers
let url = null
let headers: Record<string, string> = { 'X-Request-ID': uuidV4() }
let url
if (unref(isPublicLinkContext)) {
url = file.downloadURL
} else {
Expand All @@ -29,30 +27,26 @@ export const useDownloadFile = () => {
} else {
url = client.fileVersions.getFileVersionUrl(file.fileId, version)
}
const accessToken = store.getters['runtime/auth/accessToken']
headers = { Authorization: 'Bearer ' + accessToken }
}

// download with signing enabled
if (isUserContext && unref(isUrlSigningEnabled)) {
const httpClient = clientService.httpAuthenticated
try {
const response = await fetch(url, {
method: 'HEAD',
headers
})
const response = await httpClient.head(url)
if (response.status === 200) {
const signedUrl = await client.signUrl(url)
triggerDownloadWithFilename(signedUrl, file.name)
return
}
} catch (e) {
console.error(e)
store.dispatch('showErrorMessage', {
title: $gettext('Download failed'),
desc: $gettext('File could not be located'),
error: e
})
}
store.dispatch('showErrorMessage', {
title: $gettext('Download failed'),
desc: $gettext('File could not be located'),
status: 'danger'
})
return
}

Expand Down
8 changes: 8 additions & 0 deletions packages/web-pkg/src/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export class RuntimeError extends Error {
export class ApiError extends RuntimeError {
name = 'ApiError'
}

export class HttpError extends Error {
public response: any
constructor(message, response) {
super(message)
this.response = response
}
}
4 changes: 2 additions & 2 deletions packages/web-pkg/src/services/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import major from 'semver/functions/major'
import rcompare from 'semver/functions/rcompare'

import { RuntimeError } from 'web-pkg/src/errors'
import { HttpError, RuntimeError } from 'web-pkg/src/errors'
import { ClientService } from 'web-pkg/src/services'
import { urlJoin } from 'web-client/src/utils'
import { configurationManager } from 'web-pkg/src/configuration'
Expand Down Expand Up @@ -99,7 +99,7 @@ export class ArchiverService {
triggerDownloadWithFilename(objectUrl, fileName)
return url
} catch (e) {
throw new RuntimeError('archive could not be fetched')
throw new HttpError('archive could not be fetched', e.response)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"luxon": "^2.4.0",
"marked": "^4.0.12",
"oidc-client-ts": "^2.1.0",
"owncloud-sdk": "~3.1.0-alpha.4",
"owncloud-sdk": "~3.1.0-alpha.6",
"p-queue": "^6.6.2",
"pinia": "^2.1.3",
"portal-vue": "3.0.0",
Expand Down
17 changes: 14 additions & 3 deletions packages/web-runtime/src/store/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { AxiosError } from 'axios'

const state = {
messages: [],
quickActions: {}
}

const actions = {
showErrorMessage({ commit }, message) {
const getXRequestID = (error: AxiosError): string | null => {
const getXRequestID = (error: any): string | null => {
/**
* x-request-id response headers might be very nested in ownCloud SDK,
* only remove records if you are sure they aren't valid anymore
*/
if (error.response?.res?.res?.headers?.['x-request-id']) {
return error.response.res.res.headers['x-request-id']
}
if (error.response?.headers?.map?.['x-request-id']) {
return error.response.headers.map['x-request-id']
}
if (error.response?.res?.headers?.['x-request-id']) {
return error.response.res.headers['x-request-id']
}
if (error.response?.headers?.['x-request-id']) {
return error.response.headers['x-request-id']
}
Expand Down
Loading

0 comments on commit bce11d2

Please sign in to comment.