diff --git a/lib/client.js b/lib/client.js index 76857fe1b..df6fdfa65 100644 --- a/lib/client.js +++ b/lib/client.js @@ -212,16 +212,20 @@ 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.methodName = name; + err.request = xml; + err.response = body; + self.emit('soapError', err); callback(err); } else { try { @@ -235,6 +239,8 @@ Client.prototype._invoke = function(method, args, location, callback, options, e } error.response = response; error.body = body; + 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 d4c88692b..4d93781ec 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 with methodName', 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.methodName, 'MyOperation'); + }); + client.MyOperation({}, function(err, result) { + assert.ok(didEmitEvent); + done(); + }); + }, baseUrl); + }); }); describe('Handle non-success http status codes', function() { @@ -384,10 +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) { assert.ok(err); + console.log({err:err}); + assert.equal(err.methodName, 'MyOperation'); }); client.MyOperation({}, function(err, result) { done(); @@ -465,14 +481,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 +499,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() { @@ -499,12 +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) { didEmitEvent = true; assert.ok(err.root.Envelope.Body.Fault); + assert.equal(err.methodName, 'MyOperation'); }); client.MyOperation({}, function(err, result) { assert.ok(didEmitEvent);