Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Messing with error prototypes for ie10
- Loading branch information
1 parent
1c46280
commit 35a6532
Showing
2 changed files
with
153 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters