Permalink
Browse files

catch errors on request object and emit an error from restler

  • Loading branch information...
1 parent ba5e3d5 commit d636b615664718a51ea0cd4cf5e3397683ffa95e @danwrong danwrong committed Feb 3, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/restler.js
View
@@ -104,11 +104,11 @@ mixin(Request.prototype, {
// TODO Handle different encodings
response.setEncoding('utf8');
- response.addListener('data', function(chunk) {
+ response.on('data', function(chunk) {
body += chunk;
});
- response.addListener('end', function() {
+ response.on('end', function() {
if (self.options.parser) {
self.options.parser.call(response, body, function(parsedData) {
@@ -138,8 +138,10 @@ mixin(Request.prototype, {
_makeRequest: function() {
var self = this;
- this.request.addListener("response", function(response) {
+ this.request.on('response', function(response) {
self._responseHandler(response);
+ }).on('error', function(err) {
+ self._respond('error', null, err);
});
},
run: function() {
@@ -228,7 +230,7 @@ try {
if (data) {
var parser = new xml2js.Parser();
- parser.addListener('end', function(result) {
+ parser.on('end', function(result) {
callback(result);
});

0 comments on commit d636b61

Please sign in to comment.