File tree Expand file tree Collapse file tree 4 files changed +36
-31
lines changed Expand file tree Collapse file tree 4 files changed +36
-31
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,30 @@ export interface ImageError {
103
103
toString ( ) : string ;
104
104
}
105
105
106
+ export function wrapNativeException ( ex , errorType = typeof ex ) {
107
+ if ( typeof ex === 'string' ) {
108
+ return new Error ( ex ) ;
109
+ }
110
+ if ( ! ( ex instanceof Error ) ) {
111
+ if ( __ANDROID__ ) {
112
+ const err = new Error ( ex . toString ( ) ) ;
113
+ err [ 'nativeException' ] = ex ;
114
+ //@ts -ignore
115
+ err [ 'stackTrace' ] = com . tns . NativeScriptException . getStackTraceAsString ( ex ) ;
116
+ return err ;
117
+ }
118
+ if ( __IOS__ ) {
119
+ const err = new Error ( ex . localizedDescription ) ;
120
+ err [ 'nativeException' ] = ex ;
121
+ err [ 'code' ] = ex . code ;
122
+ err [ 'domain' ] = ex . domain ;
123
+ // TODO: we loose native stack. see how to get it
124
+ return err ;
125
+ }
126
+ }
127
+ return ex ;
128
+ }
129
+
106
130
export interface ImagePipelineConfigSetting {
107
131
isDownsampleEnabled ?: boolean ;
108
132
leakTracker ?: any ;
Original file line number Diff line number Diff line change @@ -32,8 +32,10 @@ import {
32
32
showProgressBarProperty ,
33
33
srcProperty ,
34
34
stretchProperty ,
35
- tintColorProperty
35
+ tintColorProperty ,
36
+ wrapNativeException
36
37
} from './index-common' ;
38
+ import { FailureEventData } from '@nativescript-community/ui-image' ;
37
39
38
40
let initialized = false ;
39
41
let initializeConfig : ImagePipelineConfigSetting ;
@@ -340,18 +342,6 @@ export class IntermediateEventData extends EventData {
340
342
}
341
343
}
342
344
343
- export class FailureEventData extends EventData {
344
- private _error : ImageError ;
345
-
346
- get error ( ) : ImageError {
347
- return this . _error ;
348
- }
349
-
350
- set error ( value : ImageError ) {
351
- this . _error = value ;
352
- }
353
- }
354
-
355
345
export const needUpdateHierarchy = function ( targetOrNeedsLayout : any , propertyKey ?: string | Symbol , descriptor ?: PropertyDescriptor ) : any {
356
346
if ( typeof targetOrNeedsLayout === 'boolean' ) {
357
347
return function ( target2 : any , propertyKey : string | Symbol , descriptor : PropertyDescriptor ) {
@@ -668,7 +658,7 @@ export class Img extends ImageBase {
668
658
const imageError = new ImageError ( throwable ) ;
669
659
nativeView . notify ( {
670
660
eventName,
671
- error : imageError
661
+ error : wrapNativeException ( throwable )
672
662
} as FailureEventData ) ;
673
663
}
674
664
}
@@ -681,10 +671,9 @@ export class Img extends ImageBase {
681
671
if ( nativeView ) {
682
672
const eventName = ImageBase . intermediateImageFailedEvent ;
683
673
if ( nativeView . hasListeners ( eventName ) ) {
684
- const imageError = new ImageError ( throwable ) ;
685
674
nativeView . notify ( {
686
675
eventName,
687
- error : imageError
676
+ error : wrapNativeException ( throwable )
688
677
} as FailureEventData ) ;
689
678
}
690
679
}
Original file line number Diff line number Diff line change @@ -314,21 +314,11 @@ export class IntermediateEventData {
314
314
/**
315
315
* Instances of this class are provided to the handlers of the {@link failure} and {@link intermediateImageFailed}.
316
316
*/
317
- export class FailureEventData {
318
- /**
319
- * Returns the name of the event that has been fired.
320
- */
321
- eventName : string ;
322
-
323
- /**
324
- * The object that fires the event.
325
- */
326
- object : any ;
327
-
317
+ export class FailureEventData extends EventData {
328
318
/**
329
319
* An object containing information about the status of the event.
330
320
*/
331
- error : ImageError ;
321
+ error : Error ;
332
322
}
333
323
334
324
/**
Original file line number Diff line number Diff line change @@ -16,8 +16,10 @@ import {
16
16
imageRotationProperty ,
17
17
placeholderImageUriProperty ,
18
18
srcProperty ,
19
- stretchProperty
19
+ stretchProperty ,
20
+ wrapNativeException
20
21
} from './index-common' ;
22
+ import { FailureEventData } from '@nativescript-community/ui-image' ;
21
23
22
24
export class ImageInfo implements ImageInfoBase {
23
25
constructor (
@@ -402,8 +404,8 @@ export class Img extends ImageBase {
402
404
if ( error ) {
403
405
this . notify ( {
404
406
eventName : Img . failureEvent ,
405
- error
406
- } ) ;
407
+ error : wrapNativeException ( error )
408
+ } as FailureEventData ) ;
407
409
if ( this . failureImageUri ) {
408
410
image = this . getUIImage ( this . failureImageUri ) ;
409
411
this . _setNativeImage ( image , animate ) ;
You can’t perform that action at this time.
0 commit comments