try/catch

This commit is contained in:
Thomas E Lackey 2024-02-28 19:09:29 -06:00
parent ad3e01b2ee
commit b9cdc036ed
2 changed files with 43 additions and 23 deletions

View File

@ -51,7 +51,7 @@ export class RegHelper {
const records = await this.registry.resolveNames([name]);
for (const r of records) {
// r can be null
if (!r) {
if (r) {
this.cache.set(r.id, r);
if (Array.isArray(r.names)) {
for (const n of r.names) {

View File

@ -55,12 +55,18 @@ const adjustFromState = (regStatus: any[]) => {
}
app.get('/', async (_req, res) => {
try {
const reg = new RegHelper();
const regStatus = adjustFromState(await reg.deploymentRequestStatus());
res.send(regStatus);
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
app.get('/:id', async (req, res) => {
try {
const reg = new RegHelper();
const records = adjustFromState(await reg.deploymentRequestStatus(req.params.id));
if (records.length) {
@ -68,9 +74,14 @@ app.get('/:id', async (req, res) => {
} else {
res.sendStatus(410);
}
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
app.get('/:id/log', async (req, res) => {
try {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
@ -78,10 +89,15 @@ app.get('/:id/log', async (req, res) => {
}
res.send(readFileSync(logFile));
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
// deprecated
app.get('/log/:id', async (req, res) => {
try {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
@ -89,6 +105,10 @@ app.get('/log/:id', async (req, res) => {
}
res.send(readFileSync(logFile));
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
app.listen(Config.LISTEN_PORT, Config.LISTEN_ADDR, () => {