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

feat: add global error handler #1514

Merged
merged 18 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: use JSON.stringify to format log messages
  • Loading branch information
mwear committed Oct 7, 2020
commit ed1d3eb3924922caabc4c28f0e3ee1b7ceee78ae
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ function stringifyException(ex: Exception | string): string {
if (typeof ex === 'string') {
mwear marked this conversation as resolved.
Show resolved Hide resolved
return ex;
} else {
return Object.entries(flattenException(ex))
.map(([k, v]) => `${k}: ${v}`)
.join('\n');
return JSON.stringify(flattenException(ex));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('loggingErrorHandler', () => {

const [result] = errorStub.lastCall.args;

assert.ok(result.includes(`name: ${err.name}`));
assert.ok(result.includes(`message: ${err.message}`));
assert.ok(result.includes(`randomString: ${err.randomString}`));
assert.ok(result.includes(`randomNumber: ${err.randomNumber}`));
assert.ok(result.includes(`randomArray: ${err.randomArray}`));
assert.ok(result.includes(`randomObject: ${err.randomObject}`));
assert.ok(result.includes(`stack: ${err.stack}`));
assert.ok(result.includes(err.name));
assert.ok(result.includes(err.message));
assert.ok(result.includes(err.randomString));
assert.ok(result.includes(err.randomNumber));
assert.ok(result.includes(err.randomArray));
assert.ok(result.includes(err.randomObject));
assert.ok(result.includes(JSON.stringify(err.stack)));
});

it('logs from an error', () => {
Expand All @@ -68,8 +68,8 @@ describe('loggingErrorHandler', () => {

const [result] = errorStub.lastCall.args;

assert.ok(result.includes(`name: ${err.name}`));
assert.ok(result.includes(`message: ${err.message}`));
assert.ok(result.includes(`stack: ${err.stack}`));
assert.ok(result.includes(err.name));
assert.ok(result.includes(err.message));
assert.ok(result.includes(JSON.stringify(err.stack)));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('CollectorMetricExporter - node with proto over http', () => {
callback(mockResError);
setTimeout(() => {
const response = spyLoggerError.args[0][0] as string;
assert.ok(response.includes('code: 400'));
assert.ok(response.includes('"code":"400"'));
assert.strictEqual(responseSpy.args[0][0], 1);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('CollectorTraceExporter - node with proto over http', () => {
setTimeout(() => {
const response = spyLoggerError.args[0][0] as string;

assert.ok(response.includes('code: 400'));
assert.ok(response.includes('"code":"400"'));
assert.strictEqual(responseSpy.args[0][0], 1);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('CollectorMetricExporter - web', () => {

setTimeout(() => {
const response: any = spyLoggerError.args[0][0] as string;
assert.ok(response.includes('message: sendBeacon - cannot send'));
assert.ok(response.includes('sendBeacon - cannot send'));
assert.strictEqual(spyLoggerDebug.args.length, 1);

done();
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('CollectorMetricExporter - web', () => {
request.respond(400);

const response = spyLoggerError.args[0][0] as string;
assert.ok(response.includes('code: 400'));
assert.ok(response.includes('"code":"400"'));

assert.strictEqual(spyBeacon.callCount, 0);
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('CollectorTraceExporter - web', () => {

setTimeout(() => {
const response = spyLoggerError.args[0][0] as string;
assert.ok(response.includes('message: sendBeacon - cannot send'));
assert.ok(response.includes('sendBeacon - cannot send'));
assert.strictEqual(spyLoggerDebug.args.length, 1);

done();
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('CollectorTraceExporter - web', () => {

const response = spyLoggerError.args[0][0] as string;

assert.ok(response.includes('code: 400'));
assert.ok(response.includes('"code":"400"'));

assert.strictEqual(spyBeacon.callCount, 0);
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ describe('CollectorMetricExporter - node with json over http', () => {
callback(mockResError);
setTimeout(() => {
const response = spyLoggerError.args[0][0] as string;

assert.ok(response.includes('code: 400'));
console.log(response);
assert.ok(response.includes('"code":"400"'));
assert.strictEqual(responseSpy.args[0][0], 1);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('CollectorTraceExporter - node with json over http', () => {
setTimeout(() => {
const response = spyLoggerError.args[0][0] as string;

assert.ok(response.includes('code: 400'));
assert.ok(response.includes('"code":"400"'));
assert.strictEqual(responseSpy.args[0][0], 1);
done();
});
Expand Down