Fix events stuff, improve errors
This commit is contained in:
parent
3091c6dff6
commit
652fe5c264
6 changed files with 48 additions and 16 deletions
|
@ -46,6 +46,7 @@ router.use('/*',function* (next) {
|
|||
} else {
|
||||
if (!err.status) {
|
||||
debug(err);
|
||||
this.raven.captureError(err);
|
||||
throw err;
|
||||
} else {
|
||||
this.status = err.status;
|
||||
|
@ -73,4 +74,8 @@ router.get('/(.*)', function* () {
|
|||
this.throw(404);
|
||||
});
|
||||
|
||||
export const ws = new Router();
|
||||
|
||||
ws.all('/user', user.events);
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -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)));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue