From e735f2d1416936d89a662a02bf2d303298f9a349 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Wed, 5 Oct 2022 13:10:27 +0300 Subject: [PATCH] Return Error if registry server is not available. --- server.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 3d1f9bb..5a4a44a 100755 --- a/server.js +++ b/server.js @@ -97,17 +97,22 @@ app.get('/view/:baseView', async (req, res) => { app.get('/publish', async (req, res) => { const data = await readJSONFile('./block.json'); + let responseData; - const response = await fetch(`${blocksRegistry}`, { - method: 'POST', - body: JSON.stringify(data), - headers: {'Content-Type': 'application/json'} - }); + try { + const response = await fetch(`${blocksRegistry}`, { + method: 'POST', + body: JSON.stringify(data), + headers: {'Content-Type': 'application/json'} + }); - const responseData = await response.json(); + responseData = await response.json(); + } catch (e) { + res.json({success: false, message: 'Blocks Registry server is not available.'}); + return; + } if (responseData.statusCode !== 200) { - console.log(responseData); res.json({success: false, message: 'Error on registry level.'}); return; } @@ -123,11 +128,13 @@ app.get('/publish', async (req, res) => { if (response.status !== 200) { res.json({success: false, message: "Can't upload the archive, permissions error."}); + // TODO: Need to update the registry server. await fs.unlink('./dist.zip'); return; } } + res.json({success: true}); await fs.unlink('./dist.zip');