From f38115171b1cdaa228bf64278ecca18befc8026a Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 22 Feb 2024 17:11:51 -0500 Subject: [PATCH] Error handling for registry script --- tools/registry.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/registry.js b/tools/registry.js index 958d6abf..ca74a376 100644 --- a/tools/registry.js +++ b/tools/registry.js @@ -38,19 +38,28 @@ const getEnvVars = require('./get-env-vars'); } } - await fetch(playletServer, { + const response = await fetch(playletServer, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(registry), }); + + if (!response.ok) { + throw new Error(`Failed to write registry: ${response.status} ${response.statusText}`); + } } else if (output) { if (fs.existsSync(output)) { throw new Error(`File "${output}" already exists`); } const response = await fetch(playletServer); + + if (!response.ok) { + throw new Error(`Failed to read registry: ${response.status} ${response.statusText}`); + } + const registry = await response.json(); for (const section in registry) { @@ -64,9 +73,13 @@ const getEnvVars = require('./get-env-vars'); fs.writeFileSync(output, JSON.stringify(registry, null, 4)); } else if (clear) { - await fetch(playletServer, { + const response = await fetch(playletServer, { method: 'DELETE', }); + + if (!response.ok) { + throw new Error(`Failed to clear registry: ${response.status} ${response.statusText}`); + } } else { console.error('No action specified');