From 43286d7501a230c48a4eaa47af50f61c2d324255 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Thu, 18 Jul 2024 21:50:59 +0100 Subject: [PATCH 1/3] Pass the error object to log --- src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index f44007c36..da04e6a17 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); } } } From 35e4a6aa18f337f2696306d093d12170253e8021 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Fri, 19 Jul 2024 18:24:30 +0100 Subject: [PATCH 2/3] add tests --- test/server-test.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/test/server-test.js b/test/server-test.js index cf8bfeb0f..cb406333e 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,11 @@ 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); + // console.log(test.logMessages); + // assert.strictEqual(test.logMessages.length, 1); + // assert.notStrictEqual(test.logMessages[0].tyoe, {}); done(); }); }); From 486314b6b3b044ace9768641cf8d9a7f05be31a1 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Sun, 21 Jul 2024 08:50:20 +0100 Subject: [PATCH 3/3] Remove debug remnants --- test/server-test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/server-test.js b/test/server-test.js index cb406333e..92c7afef3 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -463,9 +463,6 @@ describe('SOAP Server', function () { assert.ok(err); assert.strictEqual(err.response, response); assert.strictEqual(err.body, body); - // console.log(test.logMessages); - // assert.strictEqual(test.logMessages.length, 1); - // assert.notStrictEqual(test.logMessages[0].tyoe, {}); done(); }); });