diff --git a/lib/chartmogul/errors/index.js b/lib/chartmogul/errors/index.js index 3a294ce..d7644a0 100644 --- a/lib/chartmogul/errors/index.js +++ b/lib/chartmogul/errors/index.js @@ -6,6 +6,7 @@ const ForbiddenError = require('./forbidden-error'); const NotFoundError = require('./not-found-error'); const ResourceInvalidError = require('./resource-invalid-error'); const SchemaInvalidError = require('./schema-invalid-error'); +const InvalidParameterError = require('./invalid-parameter-error'); module.exports = { ChartMogulError, @@ -13,5 +14,6 @@ module.exports = { ForbiddenError, NotFoundError, ResourceInvalidError, - SchemaInvalidError + SchemaInvalidError, + InvalidParameterError }; diff --git a/lib/chartmogul/errors/invalid-parameter-error.js b/lib/chartmogul/errors/invalid-parameter-error.js new file mode 100644 index 0000000..0804dfa --- /dev/null +++ b/lib/chartmogul/errors/invalid-parameter-error.js @@ -0,0 +1,12 @@ +'use strict'; + +const ChartMogulError = require('./chartmogul-error'); + +class InvalidParameterError extends ChartMogulError { + constructor (message, httpStatus, response) { + super(message, httpStatus, response); + Error.captureStackTrace(this, this.constructor.name); + } +} + +module.exports = InvalidParameterError; diff --git a/lib/chartmogul/resource.js b/lib/chartmogul/resource.js index fa3fb15..64ab688 100644 --- a/lib/chartmogul/resource.js +++ b/lib/chartmogul/resource.js @@ -45,6 +45,13 @@ class Resource { return reject(error); } + if (method === 'GET' && data && data.page !== undefined) { + const error = new errors.InvalidParameterError( + "Argument 'per_page' is deprecated" + ); + return reject(error); + } + const qs = method === 'GET' ? data : {}; const body = method === 'GET' ? {} : data; diff --git a/test/chartmogul/resource.js b/test/chartmogul/resource.js index bd75b48..41bb2e2 100644 --- a/test/chartmogul/resource.js +++ b/test/chartmogul/resource.js @@ -10,6 +10,7 @@ const Customer = require('../../lib/chartmogul/customer'); describe('Resource', () => { const config = new ChartMogul.Config('token'); config.retries = 0; // no retry + it('should send basicAuth headers', done => { nock(config.API_BASE) .get('/') @@ -107,6 +108,19 @@ describe('Resource', () => { done(); }); }); + + it('should throw InvalidParameterError', done => { + nock(config.API_BASE) + .get('/customers?page=1') + .reply(200, '{}'); + + Customer.all(config, { page: 1 }) + .then(res => done(new Error('Should throw error'))) + .catch(e => { + expect(e).to.be.instanceOf(ChartMogul.ConfigurationError); + done(); + }); + }); }); describe('Resource Retry', () => { diff --git a/test/chartmogul/subscription.js b/test/chartmogul/subscription.js index 51af217..8c542cd 100644 --- a/test/chartmogul/subscription.js +++ b/test/chartmogul/subscription.js @@ -89,7 +89,7 @@ describe('Subscription', () => { expect(res).to.have.property('subscriptions'); expect(res.subscriptions).to.be.instanceof(Array); expect(res.cursor).to.eql('cursor=='); - expect(res.has_more).to.eql(false) + expect(res.has_more).to.eql(false); }); }); });