File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export function patchError(Zone: ZoneType): void {
143143 // We got called with a `new` operator AND we are subclass of ZoneAwareError
144144 // in that case we have to copy all of our properties to `this`.
145145 Object . keys ( error )
146- . concat ( 'stack' , 'message' )
146+ . concat ( 'stack' , 'message' , 'cause' )
147147 . forEach ( ( key ) => {
148148 const value = ( error as any ) [ key ] ;
149149 if ( value !== undefined ) {
Original file line number Diff line number Diff line change @@ -180,6 +180,21 @@ describe('ZoneAwareError', () => {
180180 expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
181181 } ) ;
182182
183+ it ( 'should copy cause on error that extends native' , ( ) => {
184+ class WrappedError extends Error {
185+ constructor ( error : unknown ) {
186+ super (
187+ 'wrapped' ,
188+ // @ts -ignore
189+ { cause : error } ,
190+ ) ;
191+ }
192+ }
193+ const cause = new Error ( 'original' ) ;
194+ const wrapped = new WrappedError ( cause ) as any ;
195+ expect ( wrapped . cause ) . toBe ( cause ) ;
196+ } ) ;
197+
183198 it ( 'should always have stack property even without throw' , ( ) => {
184199 // in IE, the stack will be undefined without throw
185200 // in ZoneAwareError, we will make stack always be
You can’t perform that action at this time.
0 commit comments