Skip to content

Commit 13dae16

Browse files
author
Stefano Sala
committed
Remove body from Error
This is causing a huge memory consumption when Errors are logged.
1 parent 8cc72f9 commit 13dae16

File tree

9 files changed

+67
-105
lines changed

9 files changed

+67
-105
lines changed

.eslintrc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"extends": "airbnb-base",
3+
"env": {
4+
"node": true,
5+
"es6": true
6+
},
7+
"globals": {
8+
"fetch": true,
9+
"Headers": true
10+
},
11+
"rules": {
12+
"arrow-parens": ["error", "as-needed"],
13+
"arrow-body-style": "off",
14+
"class-methods-use-this": "warn",
15+
"comma-dangle": ["error", "never"],
16+
"consistent-return": "off",
17+
"default-case": "off",
18+
"func-names": "off",
19+
"generator-star-spacing": ["error", { "before": true, "after": true }],
20+
"guard-for-in": "warn",
21+
"no-case-declarations": "warn",
22+
"no-confusing-arrow": "off",
23+
"no-continue": "off",
24+
"no-extra-boolean-cast": "warn",
25+
"no-mixed-operators": "warn",
26+
"no-new": "off",
27+
"no-param-reassign": "off",
28+
"no-path-concat": "off",
29+
"no-plusplus": "off",
30+
"no-prototype-builtins": "warn",
31+
"no-restricted-syntax": "warn",
32+
"no-return-assign": "off",
33+
"no-shadow": "off",
34+
"no-underscore-dangle": "off",
35+
"no-var": "warn",
36+
"object-property-newline": "warn",
37+
"object-shorthand": "warn",
38+
"operator-assignment": "warn",
39+
"one-var": "off",
40+
"padded-blocks": "warn",
41+
"prefer-arrow-callback": "warn",
42+
"prefer-rest-params": "warn",
43+
"prefer-spread": "warn",
44+
"prefer-template": "off",
45+
"space-before-function-paren": ["error", "never"],
46+
"strict": "off"
47+
}
48+
}

.jscsrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 74 deletions
This file was deleted.

lib/request.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class Request {
4444

4545
error(message, response, body, error) {
4646
if (!error) error = new Error(message);
47-
error.body = body;
4847
error.response = {
49-
body: response.body,
5048
statusCode: response.statusCode
5149
};
5250
return error;
@@ -120,7 +118,7 @@ class Request {
120118
return;
121119
}
122120

123-
var json = {};
121+
let json = {};
124122
if (typeof body === 'string' && body.trim() !== '') {
125123
json = JSON.parse(body.trim());
126124
} else if (typeof body === 'object') {

lib/woocommerce.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
const logger = require('./logger'),
4-
Request = require('./request');
4+
Request = require('./request'),
5+
util = require('util');
56

67
/**
78
* Constructor sets the options for the module
@@ -49,7 +50,7 @@ class WooCommerce {
4950
timeout: this.options.timeout
5051
});
5152

52-
logger.info(require('util').inspect(this.options));
53+
logger.info(util.inspect(this.options));
5354
}
5455

5556
fullPath(path) {

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"main": "lib/woocommerce.js",
66
"scripts": {
77
"exectests": "node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha",
8-
"jshint": "node_modules/.bin/jshint lib test",
9-
"jscs": "node_modules/.bin/jscs lib test",
10-
"lint": "npm run jshint && npm run jscs",
8+
"lint": "node_modules/.bin/eslint lib test --quiet",
119
"test": "npm run exectests && npm run lint"
1210
},
1311
"repository": {
@@ -30,9 +28,10 @@
3028
"homepage": "https://github.com/Receiptful/node-woocommerce",
3129
"devDependencies": {
3230
"chai": "^3.5.0",
31+
"eslint": "^3.7.1",
32+
"eslint-config-airbnb-base": "^8.0.0",
33+
"eslint-plugin-import": "^1.16.0",
3334
"istanbul": "^0.4.2",
34-
"jscs": "^2.9.0",
35-
"jshint": "^2.9.1",
3635
"mocha": "^2.4.5",
3736
"nock": "^7.2.2",
3837
"sinon": "^1.17.3"

test/.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
},
5+
"rules": {
6+
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],
7+
}
8+
}

test/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Request', () => {
3030
});
3131

3232
it('Should return an error if hostname is missing', () => {
33-
should.Throw(() => {
33+
should.throw(() => {
3434
new Request();
3535
}, Error);
3636
});

test/woocommerce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ describe('WooCommerce', () => {
1515

1616
describe('Constructor: #WooCommerce', () => {
1717
it('Should throw an error if the consumerKey or secret are missing', () => {
18-
should.Throw(() => {
18+
should.throw(() => {
1919
new WooCommerce();
2020
}, Error);
2121
});
2222

2323
it('Should throw an error if the url is missing', () => {
24-
should.Throw(() => {
24+
should.throw(() => {
2525
new WooCommerce({
2626
consumerKey: 'foo',
2727
secret: 'foo'

0 commit comments

Comments
 (0)