[
https://issues.apache.org/jira/browse/CB-12433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15857596#comment-15857596
]
Jan Doležel commented on CB-12433:
----------------------------------
Hi, yes I looked at StackOverflow. It's a combination of
http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax
and
http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript
Not sure what is the best way...
And why do it? -
https://github.com/petkaantonov/bluebird/blob/master/docs/docs/warning-explanations.md#warning-a-promise-was-rejected-with-a-non-error
And when I look at it now more thoroughly -
http://bluebirdjs.com/docs/api/catch.html ,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
Maybe the best way how to implement it would be:
{code}
function FileError(error) {
this.code = error || null;
this.message = error || null;
this.name = this.constructor.name;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(error)).stack;
}
}
FileError.prototype = Object.create(Error.prototype);
FileError.prototype.constructor = FileError;
{code}
And in future get rid of `error` property, as according to docs, error should
use `message`...
Thanks for kicking me to do more deep research :)
> Make FileError extends native Error
> -----------------------------------
>
> Key: CB-12433
> URL: https://issues.apache.org/jira/browse/CB-12433
> Project: Apache Cordova
> Issue Type: Improvement
> Components: Plugin File
> Reporter: Jan Doležel
> Priority: Minor
>
> {code}
> diff --git a/www/FileError.js b/www/FileError.js
> index 6507921..eb681d6 100644
> --- a/www/FileError.js
> +++ b/www/FileError.js
> @@ -24,8 +24,17 @@
> */
> function FileError(error) {
> this.code = error || null;
> +
> + this.name = this.constructor.name;
> + if (typeof Error.captureStackTrace === 'function') {
> + Error.captureStackTrace(this, this.constructor);
> + } else {
> + this.stack = (new Error(error)).stack;
> + }
> }
> +FileError.prototype = new Error();
> +
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]