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]); const records = await this.registry.resolveNames([name]);
for (const r of records) { for (const r of records) {
// r can be null // r can be null
if (!r) { if (r) {
this.cache.set(r.id, r); this.cache.set(r.id, r);
if (Array.isArray(r.names)) { if (Array.isArray(r.names)) {
for (const n of r.names) { for (const n of r.names) {
this.cache.set(n, r); this.cache.set(n, r);
} }
} }
} }
} }
return records[0]; return records[0];
} }

View File

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