Skip to content

Commit b96928b

Browse files
committed
Better handling of firmware load error
1 parent e9463a9 commit b96928b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Devices/MystrixSim/WebUI/src/components/FirmwarePage.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,19 @@
249249
async function fetchPackageBytes(url, init = {}) {
250250
const response = await fetch(url, init)
251251
if (!response.ok) {
252-
throw new Error(`Package request failed: HTTP ${response.status}`)
252+
let detail = ''
253+
try {
254+
const contentType = response.headers.get('content-type') || ''
255+
if (contentType.includes('application/json')) {
256+
const payload = await response.json()
257+
detail = payload?.error ? `: ${payload.error}` : ''
258+
} else {
259+
const text = (await response.text()).trim()
260+
if (text) detail = `: ${text}`
261+
}
262+
} catch {}
263+
264+
throw new Error(`Package request failed: HTTP ${response.status}${detail}`)
253265
}
254266
return await response.arrayBuffer()
255267
}

0 commit comments

Comments
 (0)