Skip to content

Commit e078068

Browse files
author
Mukul Tayal
committed
toast error for no logs to download
1 parent b3fdb9e commit e078068

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/components/v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/CustomLogsModal/CustomLogsModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const InputForSelectedOption = ({
9595
let errorString
9696
if (e.target.value === '') {
9797
errorString = 'This field is required'
98-
} else if (Number(e.target.value) < 0) {
98+
} else if (Number(e.target.value) <= 0) {
9999
errorString = 'Value must be greater than 0'
100100
} else if (customLogFilterOptions[filterTypeRadio].error) {
101101
errorString = ''

src/components/v2/appDetails/k8Resource/nodeDetail/nodeDetail.api.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,33 +188,40 @@ export const downloadLogs = async (
188188
}
189189
logsURL += `${filter}`
190190
setDownloadInProgress(true)
191-
const response = await fetch(logsURL)
192-
try {
193-
const data = await (response as any).blob()
191+
await fetch(logsURL)
192+
.then(async (response) => {
193+
try {
194+
if(response.status === 204){
195+
toast.error(response.statusText)
196+
return;
197+
}
198+
console.log('response', response)
199+
const data = await (response as any).blob()
200+
// Create a new URL object
201+
const blobUrl = URL.createObjectURL(data)
194202

195-
// Create a new URL object
196-
const blobUrl = URL.createObjectURL(data)
203+
// Create a link element
204+
const a = document.createElement('a')
205+
a.href = logsURL
206+
a.download = `podlogs-${nodeName}-${new Date().getTime()}.log`
197207

198-
// Create a link element
199-
const a = document.createElement('a')
200-
a.href = logsURL
201-
a.download = `podlogs-${nodeName}-${new Date().getTime()}.log`
208+
// Append the link element to the DOM
209+
document.body.appendChild(a)
202210

203-
// Append the link element to the DOM
204-
document.body.appendChild(a)
211+
// Programmatically click the link to start the download
212+
a.click()
205213

206-
// Programmatically click the link to start the download
207-
a.click()
208-
209-
setTimeout(() => {
210-
URL.revokeObjectURL(blobUrl)
211-
document.body.removeChild(a)
212-
}, 0)
213-
} catch (e) {
214-
toast.error(e)
215-
} finally {
216-
setDownloadInProgress(false)
217-
}
214+
setTimeout(() => {
215+
URL.revokeObjectURL(blobUrl)
216+
document.body.removeChild(a)
217+
}, 0)
218+
} catch (e) {
219+
toast.error(e)
220+
} finally {
221+
setDownloadInProgress(false)
222+
}
223+
})
224+
.catch((e) => toast.error(e))
218225
}
219226

220227
export const getLogsURL = (

0 commit comments

Comments
 (0)