diff --git a/src/server.ts b/src/server.ts index f44007c3..da04e6a1 100644 --- a/src/server.ts +++ b/src/server.ts @@ -225,7 +225,7 @@ export class Server extends EventEmitter { error = err.stack ? (this.suppressStack === true ? err.message : err.stack) : err; this._sendHttpResponse(res, /* statusCode */ 500, error); if (typeof this.log === 'function') { - this.log('error', error, req); + this.log('error', err, req); } } } diff --git a/test/server-test.js b/test/server-test.js index cf8bfeb0..92c7afef 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -100,9 +100,14 @@ describe('SOAP Server', function () { res.end(); }); + test.logs = []; + test.server.listen(15099, null, null, function () { var testSv = test.server.address(); test.soapServer = soap.listen(test.server, '/stockquote', test.service, test.wsdl); + test.soapServer.log = function (type, data, req) { + test.logs.push({ type, data, req }); + }; test.baseUrl = `http://${testSv.address}:${testSv.port}`; // windows return 0.0.0.0 as address and that is not valid to use in a request @@ -208,6 +213,11 @@ describe('SOAP Server', function () { assert.ok(err); assert.equal(err.response.status, 500); assert.ok(err.response.data.length); + const errorLog = test.logs.find(log => log.type === 'error'); + assert.ok(errorLog); + assert(errorLog.data instanceof Error); + assert.ok(errorLog.data.name, 'TypeError'); + assert.match(errorLog.data.stack, /TypeError: Cannot read properties of undefined \(reading 'description'\)/); done(); }); }); @@ -241,6 +251,14 @@ describe('SOAP Server', function () { assert.ok(err); assert.equal(err.response.status, 500); assert.ok(err.response.data.length); + const errorLog = test.logs.find(log => log.type === 'error'); + assert.ok(errorLog); + assert.notStrictEqual(errorLog.data, { + faultcode: 500, + faultstring: 'Invalid XML', + detail: 'Error: Unexpected close tag\nLine: 0\nColumn: 184\nChar: >', + statusCode: undefined + }); done(); }); }); @@ -328,9 +346,8 @@ describe('SOAP Server', function () { assert.ifError(err); client.GetLastTradePrice({ tickerSymbol: 'Promise Error' }, function (err, response, body) { assert.ok(err); - // what happens here (error and response ????) - // assert.strictEqual(err.response, response); - // assert.strictEqual(err.body, body); + assert.strictEqual(err.response, response); + assert.strictEqual(err.body, body); done(); }); }); @@ -444,9 +461,8 @@ describe('SOAP Server', function () { assert.ifError(err); client.GetLastTradePrice({ tickerSymbol: 'trigger error' }, function (err, response, body) { assert.ok(err); - // what happens here (error and response ????) - // assert.strictEqual(err.response, response); - // assert.strictEqual(err.body, body); + assert.strictEqual(err.response, response); + assert.strictEqual(err.body, body); done(); }); });