Skip to content

Commit

Permalink
Messing with error prototypes for ie10
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightgunning committed Jun 26, 2018
1 parent 1c46280 commit 35a6532
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 107 deletions.
251 changes: 146 additions & 105 deletions src/lib/errors.js
@@ -1,126 +1,167 @@
var errors = module.exports;

function addStack(err) {
/* istanbul ignore else */
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(err, constructor);
Error.captureStackTrace(err, err.constructor);
} else if (!!(new Error()).stack) { // eslint-disable-line no-extra-boolean-cast
err.stack = (new Error()).stack;
} else {
err.stack = '';
}
}

/**
* FeedError
* @class FeedError
* @access private
* @extends ErrorAbstract
* @memberof Stream.errors
* @param {String} [msg] - An error message that will probably end up in a log.
*/
errors.FeedError = function FeedError(msg) {
var instance = new Error(msg);
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
addStack(this);
return instance;
};
errors.FeedError.prototype = Object.create(Error.prototype, {
constructor: {
value: Error,
enumerable: false,
writable: true,
configurable: true
// /**
// * FeedError
// * @class FeedError
// * @access private
// * @extends ErrorAbstract
// * @memberof Stream.errors
// * @param {String} [msg] - An error message that will probably end up in a log.
// */
// errors.FeedError = function FeedError(msg) {
// var instance = new Error(msg);
// Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
// addStack(this);
// return instance;
// };
// errors.FeedError.prototype = Object.create(Error.prototype, {
// constructor: {
// value: Error,
// enumerable: false,
// writable: true,
// configurable: true
// }
// });
// if (Object.setPrototypeOf){
// Object.setPrototypeOf(errors.FeedError, Error);
// } else {
// errors.FeedError.__proto__ = Error;
// }

// /**
// * SiteError
// * @class SiteError
// * @access private
// * @extends ErrorAbstract
// * @memberof Stream.errors
// * @param {string} [msg] An error message that will probably end up in a log.
// */
// errors.SiteError = function SiteError(msg) {
// var instance = new Error(msg);
// Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
// addStack(this);
// return instance;
// };
// errors.SiteError.prototype = Object.create(Error.prototype, {
// constructor: {
// value: Error,
// enumerable: false,
// writable: true,
// configurable: true
// }
// });
// if (Object.setPrototypeOf){
// Object.setPrototypeOf(errors.SiteError, Error);
// } else {
// errors.SiteError.__proto__ = Error;
// }

// /**
// * MissingSchemaError
// * @method MissingSchemaError
// * @access private
// * @extends ErrorAbstract
// * @memberof Stream.errors
// * @param {string} msg
// */
// errors.MissingSchemaError = function (msg) {
// var instance = new Error(msg);
// Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
// addStack(this);
// return instance;
// };
// errors.MissingSchemaError.prototype = Object.create(Error.prototype, {
// constructor: {
// value: Error,
// enumerable: false,
// writable: true,
// configurable: true
// }
// });
// if (Object.setPrototypeOf){
// Object.setPrototypeOf(errors.MissingSchemaError, Error);
// } else {
// errors.MissingSchemaError.__proto__ = Error;
// }

// /**
// * StreamApiError
// * @method StreamApiError
// * @access private
// * @extends ErrorAbstract
// * @memberof Stream.errors
// * @param {string} msg
// * @param {object} data
// * @param {object} response
// */
// errors.StreamApiError = function StreamApiError(msg, data, response) {
// var instance = new Error(msg, data, response);
// Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
// addStack(this);
// return instance;
// };
// errors.StreamApiError.prototype = Object.create(Error.prototype, {
// constructor: {
// value: Error,
// enumerable: false,
// writable: true,
// configurable: true
// }
// });
// if (Object.setPrototypeOf){
// Object.setPrototypeOf(errors.StreamApiError, Error);
// } else {
// errors.StreamApiError.__proto__ = Error;
// }

class FeedError extends Error {
constructor(message) {
super(message);
this.message = message;
addStack(this);
}
});
if (Object.setPrototypeOf){
Object.setPrototypeOf(errors.FeedError, Error);
} else {
errors.FeedError.__proto__ = Error;
}

/**
* SiteError
* @class SiteError
* @access private
* @extends ErrorAbstract
* @memberof Stream.errors
* @param {string} [msg] An error message that will probably end up in a log.
*/
errors.SiteError = function SiteError(msg) {
var instance = new Error(msg);
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
addStack(this);
return instance;
};
errors.SiteError.prototype = Object.create(Error.prototype, {
constructor: {
value: Error,
enumerable: false,
writable: true,
configurable: true

class SiteError extends Error {
constructor(message) {
super(message);
this.message = message;
addStack(this);
}
});
if (Object.setPrototypeOf){
Object.setPrototypeOf(errors.SiteError, Error);
} else {
errors.SiteError.__proto__ = Error;
}

/**
* MissingSchemaError
* @method MissingSchemaError
* @access private
* @extends ErrorAbstract
* @memberof Stream.errors
* @param {string} msg
*/
errors.MissingSchemaError = function (msg) {
var instance = new Error(msg);
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
addStack(this);
return instance;
};
errors.MissingSchemaError.prototype = Object.create(Error.prototype, {
constructor: {
value: Error,
enumerable: false,
writable: true,
configurable: true
class MissingSchemaError extends Error {
constructor(message) {
super(message);
this.message = message;
addStack(this);
}
});
if (Object.setPrototypeOf){
Object.setPrototypeOf(errors.MissingSchemaError, Error);
} else {
errors.MissingSchemaError.__proto__ = Error;
}

/**
* StreamApiError
* @method StreamApiError
* @access private
* @extends ErrorAbstract
* @memberof Stream.errors
* @param {string} msg
* @param {object} data
* @param {object} response
*/
errors.StreamApiError = function StreamApiError(msg, data, response) {
var instance = new Error(msg, data, response);
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
addStack(this);
return instance;
};
errors.StreamApiError.prototype = Object.create(Error.prototype, {
constructor: {
value: Error,
enumerable: false,
writable: true,
configurable: true

class StreamApiError extends Error {
constructor(message, data, response) {
super(message);
this.message = message;
this.data = data;
this.response = response;
addStack(this);
}
});
if (Object.setPrototypeOf){
Object.setPrototypeOf(errors.StreamApiError, Error);
} else {
errors.StreamApiError.__proto__ = Error;
}

module.exports = {
FeedError,
SiteError,
MissingSchemaError,
StreamApiError
}
9 changes: 7 additions & 2 deletions test/unit/node/redirect_test.js
Expand Up @@ -133,9 +133,14 @@ describe('[UNIT] Redirect URL\'s', function() {

it('should fail creating email redirects on invalid targets', function() {
var self = this;
expect(function() {

function toThrow() {
self.client.createRedirectUrl('google.com', 'tommaso', []);
}).to.throwException(errors.MissingSchemaError);
}

expect(toThrow).to.throwException(function(e) {
expect(e).to.be.a(errors.MissingSchemaError);
});
});

});

0 comments on commit 35a6532

Please sign in to comment.