Browse Source

Return Error if registry server is not available.

test-gpt-generated
Roman Axelrod 3 years ago
parent
commit
e735f2d141
  1. 11
      server.js

11
server.js

@ -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;
try {
const response = await fetch(`${blocksRegistry}`, { const response = await fetch(`${blocksRegistry}`, {
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
headers: {'Content-Type': 'application/json'} 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');

Loading…
Cancel
Save