mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 15:32:24 +00:00
In /v1/update, return 202 when we're not updating immediately
We also add a catch to any errors when getting configuration, and send 503 in this case, even if it's unlikely. Change-type: patch Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
This commit is contained in:
parent
8f07bf62de
commit
9961ebb41d
@ -920,17 +920,33 @@ export class APIBinder {
|
||||
router.post('/v1/update', (req, res) => {
|
||||
apiBinder.eventTracker.track('Update notification');
|
||||
if (apiBinder.readyForUpdates) {
|
||||
this.config.get('instantUpdates').then(instantUpdates => {
|
||||
if (instantUpdates) {
|
||||
apiBinder.getAndSetTargetState(req.body.force, true).catch(_.noop);
|
||||
} else {
|
||||
console.log(
|
||||
'Ignoring update notification because instant updates are disabled',
|
||||
);
|
||||
}
|
||||
});
|
||||
this.config
|
||||
.get('instantUpdates')
|
||||
.then(instantUpdates => {
|
||||
if (instantUpdates) {
|
||||
apiBinder
|
||||
.getAndSetTargetState(req.body.force, true)
|
||||
.catch(_.noop);
|
||||
res.sendStatus(204);
|
||||
} else {
|
||||
console.log(
|
||||
'Ignoring update notification because instant updates are disabled',
|
||||
);
|
||||
res.sendStatus(202);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
const msg =
|
||||
err.message != null
|
||||
? err.message
|
||||
: err != null
|
||||
? err
|
||||
: 'Unknown error';
|
||||
res.status(503).send(msg);
|
||||
});
|
||||
} else {
|
||||
res.sendStatus(202);
|
||||
}
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
return router;
|
||||
|
Loading…
Reference in New Issue
Block a user