Commit 742e2089 by zCaesar

add handler error from redis

parent cefb2042
......@@ -61,8 +61,13 @@ module.exports = function (options = {}) {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
}
// save on redis before send response
try {
on_message_redis(req.body.client_id, req.body.payload, topic)
res.send(response);
}
catch (e) {
res.send({ result: { error: 'not allowed' } });
}
next();
}
else {
......
......@@ -62,28 +62,33 @@ module.exports = function (options = {}) {
}
var cachekey = 'auth:' + req.body.client_id + ':' + req.body.username + ':' + req.body.password;
var authstatus = cache.get(cachekey);
if (typeof (authstatus) == 'undefined') {
// if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
cache.set(cachekey, result);
if (result) {
// authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
// cache.set(cachekey, result);
// if (result) {
try {
on_register_redis(req.body.client_id)
res.send({ result: 'ok' });
} else {
}
catch (e) {
res.send({ result: { error: 'not allowed' } });
}
// } else {
// res.send({ result: { error: 'not allowed' } });
// }
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
});
}
else {
if (authstatus) {
on_register_redis(req.body.client_id)
res.send({ result: 'ok' });
} else {
res.send({ result: { error: 'not allowed' } });
}
}
// });
// }
// else {
// if (authstatus) {
// on_register_redis(req.body.client_id)
// res.send({ result: 'ok' });
// } else {
// res.send({ result: { error: 'not allowed' } });
// }
// }
next();
}
else {
......
......@@ -21,6 +21,18 @@ function on_message_redis(deviceid, payload, topic) { // first time to access on
}
module.exports.on_message_redis = on_message_redis
redis.on("error", (error) => {
console.log("Redis connection error", error);
});
redis.on('reconnecting', function reconnecting() {
console.log('Connection reestablished');
});
redis.on('connect', function connect() {
console.log('connecting');
});
function setValue(deviceid, payload, topic) {
var dateNow = Math.floor(Date.now() / 1000)
var keys = 'deviceid:' + deviceid
......
......@@ -12,6 +12,18 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
module.exports.on_offline_redis = on_offline_redis
redis.on("error", (error) => {
console.log("Redis connection error", error);
});
redis.on('reconnecting', function reconnecting() {
console.log('Connection reestablished');
});
redis.on('connect', function connect() {
console.log('connecting');
});
function setValue(deviceid) {
var dateNow = Math.floor(Date.now() / 1000)
var keys = 'deviceid:' + deviceid
......
......@@ -14,6 +14,18 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
}
module.exports.on_register_redis = on_register_redis
redis.on("error", (error) => {
console.log("Redis connection error", error);
});
redis.on('reconnecting', function reconnecting() {
console.log('Connection reestablished');
});
redis.on('connect', function connect() {
console.log('connecting');
});
function setValue(deviceid) {
var dateNow = Math.floor(Date.now() / 1000)
var keys = 'deviceid:' + deviceid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment