Skip to content

Commit

Permalink
#42 catching error for malformed backend
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Mar 21, 2013
1 parent e8b469a commit aeb3d08
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ Sync.prototype.error = function(err) {
};

Sync.prototype.handle = function(backend, req, callback) {
var self = this;
var responder = new EventEmitter();
var res = this.init(req, responder);

responder.once('respond', function(err, result) {
if (err) {
callback(self.error(err));
} else {
callback(null, result);
}
});

backend.handle(req, res, function(err) {
if (err) responder.emit('respond', err);
});
var self = this;
var responder = new EventEmitter();
var res = this.init(req, responder);

responder.once('respond', function(err, result) {
if (err) {
callback(self.error(err));
} else {
callback(null, result);
}
});
// #42 catching error for malformed backend
try{
backend.handle(req, res, function(err) {
if (err) responder.emit('respond', err);
});
} catch( e ){
responder.emit('respond', false);
}
};

0 comments on commit aeb3d08

Please sign in to comment.