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

Commit

Permalink
fix(clientErrorLogger): format console error message (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
infoxicator authored Dec 2, 2020
1 parent 2d9c766 commit 03da190
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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

0 comments on commit 03da190

Please sign in to comment.