Return Error if registry server is not available.

This commit is contained in:
2022-10-05 13:10:27 +03:00
parent 804c504c06
commit e735f2d141
+14 -7
View File
@@ -97,17 +97,22 @@ app.get('/view/:baseView', async (req, res) => {
app.get('/publish', async (req, res) => { app.get('/publish', async (req, res) => {
const data = await readJSONFile('./block.json'); const data = await readJSONFile('./block.json');
let responseData;
const response = await fetch(`${blocksRegistry}`, { try {
method: 'POST', const response = await fetch(`${blocksRegistry}`, {
body: JSON.stringify(data), method: 'POST',
headers: {'Content-Type': 'application/json'} 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) { if (responseData.statusCode !== 200) {
console.log(responseData);
res.json({success: false, message: 'Error on registry level.'}); res.json({success: false, message: 'Error on registry level.'});
return; return;
} }
@@ -123,11 +128,13 @@ app.get('/publish', async (req, res) => {
if (response.status !== 200) { if (response.status !== 200) {
res.json({success: false, message: "Can't upload the archive, permissions error."}); res.json({success: false, message: "Can't upload the archive, permissions error."});
// TODO: Need to update the registry server.
await fs.unlink('./dist.zip'); await fs.unlink('./dist.zip');
return; return;
} }
} }
res.json({success: true}); res.json({success: true});
await fs.unlink('./dist.zip'); await fs.unlink('./dist.zip');