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,14 +51,14 @@ 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) {
this.cache.set(n, r);
}
}
}
}
}
return records[0];
}

View File

@ -55,40 +55,60 @@ const adjustFromState = (regStatus: any[]) => {
}
app.get('/', async (_req, res) => {
const reg = new RegHelper();
const regStatus = adjustFromState(await reg.deploymentRequestStatus());
res.send(regStatus);
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) => {
const reg = new RegHelper();
const records = adjustFromState(await reg.deploymentRequestStatus(req.params.id));
if (records.length) {
res.send(records[0]);
} else {
res.sendStatus(410);
try {
const reg = new RegHelper();
const records = adjustFromState(await reg.deploymentRequestStatus(req.params.id));
if (records.length) {
res.send(records[0]);
} else {
res.sendStatus(410);
}
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
app.get('/:id/log', async (req, res) => {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
return;
}
try {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
return;
}
res.send(readFileSync(logFile));
res.send(readFileSync(logFile));
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
// deprecated
app.get('/log/:id', async (req, res) => {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
return;
}
try {
const logFile = logForRequest(req.params.id);
if (!logFile) {
res.sendStatus(410);
return;
}
res.send(readFileSync(logFile));
res.send(readFileSync(logFile));
} catch (e) {
console.error(e);
res.sendStatus(500);
}
});
app.listen(Config.LISTEN_PORT, Config.LISTEN_ADDR, () => {