cleaned up some more code

This commit is contained in:
Daniel Sommer 2022-02-24 11:51:21 +01:00
parent 35b8c55966
commit 4dd916997e

View file

@ -64,14 +64,7 @@ function handleRequests() {
// POST '/poweroff' // POST '/poweroff'
app.post('/' + MODE_POWEROFF, (request, response) => { app.post('/' + MODE_POWEROFF, (request, response) => {
logger.http(request); logger.http(request);
blinkstick.powerOff(parser.parseRequest(request.body, MODE_POWEROFF)) handlePowerOff(parser.parseRequest(request.body, MODE_POWEROFF), response);
.then((result) => {
response.end(JSON.stringify(result));
})
.catch((err) => {
response.status(500);
response.end(JSON.stringify({status: 'error', error: err.message}));
});
}); });
} }
@ -79,8 +72,9 @@ async function handleSimpleAnimation(config, response) {
try { try {
response.end(JSON.stringify(await blinkstick.simple(config))); response.end(JSON.stringify(await blinkstick.simple(config)));
} catch (err) { } catch (err) {
logger.error(err);
response.status(500); response.status(500);
response.end({status: 'error', error: err}); response.end(JSON.stringify({status: 'error', error: err.message}));
} }
} }
@ -99,8 +93,18 @@ async function handleComplexAnimation(config, response) {
if (response === undefined) { if (response === undefined) {
return; return;
} }
logger.error(err);
response.status(500); response.status(500);
response.end({status: 'error', error: err}); response.end(JSON.stringify({status: 'error', error: err.message}));
}
}
async function handlePowerOff(config, response) {
try {
response.end(JSON.stringify(await blinkstick.powerOff(config)));
} catch (err) {
response.status(500);
response.end(JSON.stringify({status: 'error', error: err.message}));
} }
} }