Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(clientErrorLogger): format console error message #382

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion __tests__/server/middleware/clientErrorLogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

import { createRequest, createResponse } from 'node-mocks-http';
import util from 'util';

describe('clientErrorLogger', () => {
let clientErrorLogger;
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.spyOn(util, 'inspect').mockImplementation(() => {});

function load(nodeEnv) {
if (typeof nodeEnv !== 'string') {
Expand Down Expand Up @@ -96,7 +98,8 @@ describe('clientErrorLogger', () => {
console.error.mockClear();
clientErrorLogger(req, res);
expect(console.error).toHaveBeenCalledTimes(1);
const logged = console.error.mock.calls[0][0];
expect(util.inspect).toHaveBeenCalledTimes(1);
const logged = util.inspect.mock.calls[0][0];
expect(logged).toBeInstanceOf(Error);
expect(logged).toHaveProperty('name', 'ClientReportedError');
expect(logged).toHaveProperty('stack', 'Error: something broke\n at methodA (resource-a.js:1:1)\n at methodB (resource-b.js:1:1)\n');
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@americanexpress/fetch-enhancers": "^1.0.1",
"@americanexpress/lumberjack": "^1.1.4",
"@americanexpress/one-app-bundler": "^6.10.0",
"@americanexpress/one-app-ducks": "^4.2.0",
"@americanexpress/one-app-ducks": "^4.2.2",
"@americanexpress/one-app-router": "^1.1.0",
"@americanexpress/vitruvius": "^2.0.2",
"abort-controller": "^3.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/server/middleware/clientErrorLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

// /_/report/errors
import util from 'util';

const nodeEnvIsDevelopment = process.env.NODE_ENV === 'development';

export default function clientErrorLogger(req, res) {
Expand Down Expand Up @@ -53,7 +55,7 @@ export default function clientErrorLogger(req, res) {
correlationId,
},
});
console.error(err);
console.error(util.inspect(err, false, 10, true));
});
} else {
// drop on the floor, this is the wrong interface
Expand Down