From 2dbba8709892c62f54b5d69caee81c0161f455e5 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 15 Sep 2025 21:12:00 +0200 Subject: [PATCH] fix: firmware upload failure --- index.js | 16 +++++++++++++++- public/scripts/api-client.js | 8 +++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3725c9f..2083466 100644 --- a/index.js +++ b/index.js @@ -645,7 +645,21 @@ app.post('/api/node/update', async (req, res) => { try { const updateResult = await nodeClient.updateFirmware(uploadedFile.data, uploadedFile.name); - console.log(`Firmware upload to SPORE device ${nodeIp} completed successfully:`, updateResult); + console.log(`Firmware upload to SPORE device ${nodeIp} completed:`, updateResult); + + // Check if the SPORE device reported a failure + if (updateResult && updateResult.status === 'FAIL') { + console.error(`SPORE device ${nodeIp} reported firmware update failure:`, updateResult.message); + return res.status(400).json({ + success: false, + error: 'Firmware update failed', + message: updateResult.message || 'Firmware update failed on device', + nodeIp: nodeIp, + fileSize: uploadedFile.data.length, + filename: uploadedFile.name, + result: updateResult + }); + } res.json({ success: true, diff --git a/public/scripts/api-client.js b/public/scripts/api-client.js index 4d3b817..65d3a13 100644 --- a/public/scripts/api-client.js +++ b/public/scripts/api-client.js @@ -94,13 +94,19 @@ class ApiClient { async uploadFirmware(file, nodeIp) { const formData = new FormData(); formData.append('file', file); - return this.request(`/api/node/update`, { + const data = await this.request(`/api/node/update`, { method: 'POST', query: { ip: nodeIp }, body: formData, isForm: true, headers: {}, }); + // Some endpoints may return HTTP 200 with success=false on logical failure + if (data && data.success === false) { + const message = data.message || 'Firmware upload failed'; + throw new Error(message); + } + return data; } }