Skip to content

Instantly share code, notes, and snippets.

@alastaircoote
Created September 15, 2016 17:03
Show Gist options
  • Save alastaircoote/5aeeb7ea77fc14904ca1220ccfdc2459 to your computer and use it in GitHub Desktop.
Save alastaircoote/5aeeb7ea77fc14904ca1220ccfdc2459 to your computer and use it in GitHub Desktop.
const trySubscribeAction = function(id, action, log) {
return Promise.resolve()
.then( () => {
if (action == "subscribe") {
return subscribePromise(id);
} else {
return unsubscribePromise(id);
}
})
.then( (result) => {
log.info({result: result}, "Request success");
})
.catch( (error) => {
log.error({error: err}, "Request failed");
})
}
const subscribe = function(req, res, next) {
let deviceId = req.params["id"];
req.log.info({
id: deviceID,
action: "subscribe"
}, "Received request.");
return trySubscribeAction(deviceId, "subscribe");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment