Skip to content

Commit 7c286e6

Browse files
committed
feat: add error handling for 204
1 parent c6e7292 commit 7c286e6

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ export const EXCLUDED_FALSY_VALUES = [undefined, null, '', NaN] as const
477477

478478
export const API_STATUS_CODES = {
479479
OK: 200,
480+
NO_CONTENT: 204,
480481
BAD_REQUEST: 400,
481482
UNAUTHORIZED: 401,
482483
PERMISSION_DENIED: 403,

src/Shared/Components/CICDHistory/Artifacts.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ const Artifacts = ({
155155
async function handleArtifact() {
156156
await handleDownload({
157157
downloadUrl: downloadArtifactUrl,
158-
showFilePreparingToast: true,
159158
fileName: `${buildId || triggerId}.zip`,
160159
})
161160
}

src/Shared/Hooks/UseDownload/UseDownload.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ const useDownload = () => {
4545
const a = document.createElement('a')
4646
a.href = blobUrl
4747

48-
// Get filename from response headers
49-
const defaultFileName = response.headers
50-
.get('content-disposition')
51-
.split(';')
52-
.find((n) => n.includes('filename='))
53-
.replace('filename=', '')
54-
.trim()
55-
a.download = fileName || defaultFileName || 'file.tgz'
48+
a.download =
49+
fileName ||
50+
response.headers // File name from response headers
51+
?.get('content-disposition')
52+
?.split(';')
53+
?.find((n) => n.includes('filename='))
54+
?.replace('filename=', '')
55+
.trim() ||
56+
'file.tgz'
5657

5758
// Append the link element to the DOM
5859
document.body.appendChild(a)
@@ -69,6 +70,8 @@ const useDownload = () => {
6970
if (showSuccessfulToast) {
7071
toast.success(downloadSuccessToastContent)
7172
}
73+
} else if (response.status === API_STATUS_CODES.NO_CONTENT) {
74+
throw new Error('No content to download')
7275
} else {
7376
const jsonResponseError: ServerErrors = await response?.json()
7477
throw new ServerErrors(jsonResponseError)

0 commit comments

Comments
 (0)