From 8bf902bd122a8f2d42d1231b95e0df5a8b7821b7 Mon Sep 17 00:00:00 2001 From: Ying Tang Date: Wed, 29 Jul 2015 23:48:27 -0700 Subject: [PATCH 1/4] add name to event data and emit soapError when error is received --- lib/client.js | 7 +++++-- test/client-test.js | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/client.js b/lib/client.js index 76857fe1b..703641dd0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -212,16 +212,18 @@ Client.prototype._invoke = function(method, args, location, callback, options, e self.lastRequest = xml; self.emit('message', message); - self.emit('request', xml); + self.emit('request', xml, name); req = self.httpClient.request(location, xml, function(err, response, body) { var result; var obj; self.lastResponse = body; self.lastResponseHeaders = response && response.headers; - self.emit('response', body); + self.emit('response', body, name); if (err) { + err.name = name; + self.emit('soapError', err); callback(err); } else { try { @@ -235,6 +237,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e } error.response = response; error.body = body; + error.name = name; self.emit('soapError', error); return callback(error, response, body, null); } diff --git a/test/client-test.js b/test/client-test.js index d4c88692b..722c603ee 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -465,14 +465,15 @@ describe('SOAP Client', function() { }, baseUrl); }); - it('Should emit the "request" event with entire XML message', function (done) { + it('Should emit the "request" event with entire XML message and name', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('request', function (xml) { + client.on('request', function (xml, name) { didEmitEvent = true; // Should contain entire soap message assert.equal(typeof xml, 'string'); assert.notEqual(xml.indexOf('soap:Envelope'), -1); + assert.equal(name, 'MyOperation'); }); client.MyOperation({}, function() { @@ -482,14 +483,15 @@ describe('SOAP Client', function() { }, baseUrl); }); - it('Should emit the "response" event with Soap Body string', function (done) { + it('Should emit the "response" event with Soap Body string and name', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('response', function (xml) { + client.on('response', function (xml, name) { didEmitEvent = true; // Should contain entire soap message assert.equal(typeof xml, 'string'); assert.equal(xml.indexOf('soap:Envelope'), -1); + assert.equal(name, 'MyOperation'); }); client.MyOperation({}, function() { @@ -505,6 +507,7 @@ describe('SOAP Client', function() { client.on('soapError', function(err) { didEmitEvent = true; assert.ok(err.root.Envelope.Body.Fault); + assert.equal(err.name, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent); From 7b6d33bdea707c6aec3ba32681bc9ada1a5ddd42 Mon Sep 17 00:00:00 2001 From: Ying Tang Date: Thu, 30 Jul 2015 13:44:10 -0700 Subject: [PATCH 2/4] one more test --- test/client-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/client-test.js b/test/client-test.js index 722c603ee..274f4691d 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -351,6 +351,20 @@ describe('SOAP Client', function() { }); }, baseUrl); }); + + it('should emit a \'soapError\' event', function (done) { + soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { + var didEmitEvent = false; + client.on('soapError', function(err) { + didEmitEvent = true; + assert.equal(err.name, 'MyOperation'); + }); + client.MyOperation({}, function(err, result) { + assert.ok(didEmitEvent); + done(); + }); + }, baseUrl); + }); }); describe('Handle non-success http status codes', function() { @@ -388,6 +402,7 @@ describe('SOAP Client', function() { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { client.on('soapError', function(err) { assert.ok(err); + assert.equal(err.name, 'MyOperation'); }); client.MyOperation({}, function(err, result) { done(); From b754cfd14d6d2d5d2a9e8b99223c2936738f2e7b Mon Sep 17 00:00:00 2001 From: Ying Tang Date: Thu, 30 Jul 2015 13:47:05 -0700 Subject: [PATCH 3/4] add name as second argument for soapError --- lib/client.js | 6 ++---- test/client-test.js | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/client.js b/lib/client.js index 703641dd0..1424cad08 100644 --- a/lib/client.js +++ b/lib/client.js @@ -222,8 +222,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e self.emit('response', body, name); if (err) { - err.name = name; - self.emit('soapError', err); + self.emit('soapError', err, name); callback(err); } else { try { @@ -237,8 +236,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e } error.response = response; error.body = body; - error.name = name; - self.emit('soapError', error); + self.emit('soapError', error, name); return callback(error, response, body, null); } diff --git a/test/client-test.js b/test/client-test.js index 274f4691d..774db988a 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -355,9 +355,9 @@ describe('SOAP Client', function() { it('should emit a \'soapError\' event', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('soapError', function(err) { + client.on('soapError', function(err, name) { didEmitEvent = true; - assert.equal(err.name, 'MyOperation'); + assert.equal(name, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent); @@ -400,9 +400,9 @@ describe('SOAP Client', function() { it('should emit a \'soapError\' event', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { - client.on('soapError', function(err) { + client.on('soapError', function(err, name) { assert.ok(err); - assert.equal(err.name, 'MyOperation'); + assert.equal(name, 'MyOperation'); }); client.MyOperation({}, function(err, result) { done(); @@ -519,10 +519,10 @@ describe('SOAP Client', function() { it('should emit a \'soapError\' event', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('soapError', function(err) { + client.on('soapError', function(err, name) { didEmitEvent = true; assert.ok(err.root.Envelope.Body.Fault); - assert.equal(err.name, 'MyOperation'); + assert.equal(name, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent); From 48a708bfca7a2830995b7390ca0c8f9b21bd6caf Mon Sep 17 00:00:00 2001 From: Ying Tang Date: Thu, 30 Jul 2015 16:05:24 -0700 Subject: [PATCH 4/4] add request, response and methodName to soapError data --- lib/client.js | 9 +++++++-- test/client-test.js | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/client.js b/lib/client.js index 1424cad08..df6fdfa65 100644 --- a/lib/client.js +++ b/lib/client.js @@ -222,7 +222,10 @@ Client.prototype._invoke = function(method, args, location, callback, options, e self.emit('response', body, name); if (err) { - self.emit('soapError', err, name); + err.methodName = name; + err.request = xml; + err.response = body; + self.emit('soapError', err); callback(err); } else { try { @@ -236,7 +239,9 @@ Client.prototype._invoke = function(method, args, location, callback, options, e } error.response = response; error.body = body; - self.emit('soapError', error, name); + error.request = xml; + error.methodName = name; + self.emit('soapError', error); return callback(error, response, body, null); } diff --git a/test/client-test.js b/test/client-test.js index 774db988a..4d93781ec 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -352,12 +352,12 @@ describe('SOAP Client', function() { }, baseUrl); }); - it('should emit a \'soapError\' event', function (done) { + it('should emit a \'soapError\' event with methodName', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('soapError', function(err, name) { + client.on('soapError', function(err) { didEmitEvent = true; - assert.equal(name, 'MyOperation'); + assert.equal(err.methodName, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent); @@ -398,11 +398,12 @@ describe('SOAP Client', function() { }, baseUrl); }); - it('should emit a \'soapError\' event', function (done) { + it('should emit a \'soapError\' event with methodName', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { - client.on('soapError', function(err, name) { + client.on('soapError', function(err) { assert.ok(err); - assert.equal(name, 'MyOperation'); + console.log({err:err}); + assert.equal(err.methodName, 'MyOperation'); }); client.MyOperation({}, function(err, result) { done(); @@ -516,13 +517,13 @@ describe('SOAP Client', function() { }, baseUrl); }); - it('should emit a \'soapError\' event', function (done) { + it('should emit a \'soapError\' event with methodName', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) { var didEmitEvent = false; - client.on('soapError', function(err, name) { + client.on('soapError', function(err) { didEmitEvent = true; assert.ok(err.root.Envelope.Body.Fault); - assert.equal(name, 'MyOperation'); + assert.equal(err.methodName, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent);