Fix events stuff, improve errors

This commit is contained in:
Jonathan Cremin 2015-08-23 01:05:20 +01:00
parent 3091c6dff6
commit 652fe5c264
6 changed files with 48 additions and 16 deletions

View file

@ -65,16 +65,23 @@ export function* events() {
let json;
try{
json = JSON.parse(message);
} catch(e) {
} catch(err) {
debug('Invalid JSON for socket auth');
this.websocket.send('Invalid authentication message. Bad JSON?');
this.raven.captureError(err);
}
const reply = yield this.redis.get(json.authorization);
if (reply) {
pubsub.subscribe('/user/' + reply);
debug('Subscribed to: /user/%s', reply);
} else {
this.websocket.send('Invalid authentication token.');
try {
const reply = yield this.redis.get(json.authorization);
if (reply) {
pubsub.subscribe('/user/' + reply);
this.websocket.send('{"status":"active"}');
debug('Subscribed to: /user/%s', reply);
} else {
this.websocket.send('Invalid authentication token.');
}
} catch(err) {
debug(err);
this.raven.captureError(err);
}
}.bind(this)));
});