Skip to content

Commit 5025f84

Browse files
authored
Merge pull request #14 from Receiptful/feature/remove-body-error
Remove body from Error
2 parents 8cc72f9 + 96b7859 commit 5025f84

File tree

9 files changed

+81
-109
lines changed

9 files changed

+81
-109
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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ class Request {
4242
return oauth.authorize(req);
4343
}
4444

45-
error(message, response, body, error) {
45+
error(message, response, 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;
@@ -100,10 +98,20 @@ class Request {
10098
return;
10199
}
102100

101+
if (response === -1 || body === -1) {
102+
const msg = 'A meaningless error has occurred, returning -1. ' +
103+
'This could be the result of an incorrect folder setup.';
104+
const error = this.error(msg, response);
105+
logger.error(msg);
106+
reject(error);
107+
cb(error, body, response);
108+
return;
109+
}
110+
103111
// Handle error codes between 400 & 600
104112
if (response.statusCode >= 400 && response.statusCode < 600) {
105113
const msg = `Request failed with code: ${response.statusCode}`;
106-
const error = this.error(msg, response, body);
114+
const error = this.error(msg, response);
107115

108116
logger.error(msg);
109117
reject(error);
@@ -120,7 +128,7 @@ class Request {
120128
return;
121129
}
122130

123-
var json = {};
131+
let json = {};
124132
if (typeof body === 'string' && body.trim() !== '') {
125133
json = JSON.parse(body.trim());
126134
} else if (typeof body === 'object') {
@@ -129,7 +137,7 @@ class Request {
129137

130138
if (json.hasOwnProperty('error') || json.hasOwnProperty('errors')) {
131139
const errorMessage = json.error || JSON.stringify(json.errors);
132-
const serverError = this.error(errorMessage, response, body);
140+
const serverError = this.error(errorMessage, response);
133141
cb(serverError, body, response);
134142
reject(serverError);
135143
return;
@@ -142,7 +150,7 @@ class Request {
142150
} catch (e) {
143151

144152
const malformedMsg = `Error parsing response body: ${e.message || e}`;
145-
const malformedError = this.error(malformedMsg, body, response, e);
153+
const malformedError = this.error(malformedMsg, response, e);
146154

147155
logger.error(malformedMsg);
148156
cb(malformedError, body, response);

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)