Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3CCAE200C15 for ; Wed, 8 Feb 2017 08:57:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3B228160B5A; Wed, 8 Feb 2017 07:57:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 86508160B4E for ; Wed, 8 Feb 2017 08:57:48 +0100 (CET) Received: (qmail 18163 invoked by uid 500); 8 Feb 2017 07:57:47 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 18147 invoked by uid 99); 8 Feb 2017 07:57:47 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Feb 2017 07:57:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 12DBFC0770 for ; Wed, 8 Feb 2017 07:57:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Bh87JRJbpmTU for ; Wed, 8 Feb 2017 07:57:44 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 4C1D75F298 for ; Wed, 8 Feb 2017 07:57:44 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 52919E044B for ; Wed, 8 Feb 2017 07:57:42 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id A80742528B for ; Wed, 8 Feb 2017 07:57:41 +0000 (UTC) Date: Wed, 8 Feb 2017 07:57:41 +0000 (UTC) From: =?utf-8?Q?Jan_Dole=C5=BEel_=28JIRA=29?= To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CB-12433) Make FileError extends native Error MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 08 Feb 2017 07:57:49 -0000 [ https://issues.apache.org/jira/browse/CB-12433?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D158575= 96#comment-15857596 ]=20 Jan Dole=C5=BEel commented on CB-12433: ---------------------------------- Hi, yes I looked at StackOverflow. It's a combination of http://stackoverfl= ow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax and= http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-erro= r-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-erro= r 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/Refere= nce/Global_Objects/Error#Custom_Error_Types Maybe the best way how to implement it would be: {code} function FileError(error) { this.code =3D error || null; this.message =3D error || null; this.name =3D this.constructor.name; if (typeof Error.captureStackTrace =3D=3D=3D 'function') { Error.captureStackTrace(this, this.constructor); } else { this.stack =3D (new Error(error)).stack; } } FileError.prototype =3D Object.create(Error.prototype); FileError.prototype.constructor =3D FileError; {code} And in future get rid of `error` property, as according to docs, error sho= uld 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=C5=BEel > 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 =3D error || null; > + > + this.name =3D this.constructor.name; > + if (typeof Error.captureStackTrace =3D=3D=3D 'function') { > + Error.captureStackTrace(this, this.constructor); > + } else { > + this.stack =3D (new Error(error)).stack; > + } > } > +FileError.prototype =3D new Error(); > + > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org