Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate many library api's, unify others #752

Merged
merged 10 commits into from
Jan 9, 2020
Merged
51 changes: 0 additions & 51 deletions lib/Error.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
'use strict';

const utils = require('./utils');

/**
* StripeError is the base error from which all other more specific Stripe errors derive.
* Specifically for errors returned from Stripe's REST API.
*/
class StripeError extends Error {
constructor(raw = {}) {
super(raw.message);
// This splat is here for back-compat and should be removed in the next major version.
this.populate(...arguments);
this.type = this.constructor.name;
}

/**
* DEPRECATED
* This will be inlined in the constructor in the future.
*/
populate(raw) {
this.raw = raw;
if (!raw || typeof raw !== 'object') {
return;
}

this.rawType = raw.type;
this.code = raw.code;
this.param = raw.param;
Expand Down Expand Up @@ -60,21 +46,6 @@ class StripeError extends Error {
return new GenericError('Generic', 'Unknown Error');
}
}

/**
* DEPRECATED
* Please use class inheritance instead.
*/
static extend(options) {
const type = options.type;
class CustomError extends StripeError {}
Object.defineProperty(CustomError, 'name', {
value: type,
});
delete options.type;
Object.assign(CustomError.prototype, options);
return CustomError;
}
}

// Specific Stripe Error types:
Expand Down Expand Up @@ -145,28 +116,6 @@ class StripeIdempotencyError extends StripeError {}
*/
class StripeInvalidGrantError extends StripeError {}

/**
* DEPRECATED
* This is here for backwards compatibility and will be removed in the next major version.
*/
function _Error(raw) {
this.populate(...arguments);
this.stack = new Error(this.message).stack;
}
_Error.prototype = Object.create(Error.prototype);
_Error.prototype.type = 'GenericError';
_Error.prototype.populate = function(type, message) {
this.type = type;
this.message = message;
};
_Error.extend = utils.protoExtend;

/**
* DEPRECATED.
* Do not use the default export; it may be removed or change in a future version.
*/
module.exports = _Error;

module.exports.StripeError = StripeError;
module.exports.StripeCardError = StripeCardError;
module.exports.StripeInvalidRequestError = StripeInvalidRequestError;
Expand Down
Loading