Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the error object to log #1246

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
31 changes: 25 additions & 6 deletions test/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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, {});
ikonst marked this conversation as resolved.
Show resolved Hide resolved
done();
});
});
Expand Down
Loading