From 5cd8a1fc2a044af77d05f97026f43f0c9fdb5e5e Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 13 Jun 2018 03:45:54 -0700 Subject: [PATCH] fix(Image): catch Response content may not be converted to an Image (#5856) closes https://github.com/NativeScript/nativescript-angular/issues/851 closes https://github.com/NativeScript/NativeScript/issues/3381 --- tns-core-modules/http/http.ts | 2 +- tns-core-modules/ui/image/image-common.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tns-core-modules/http/http.ts b/tns-core-modules/http/http.ts index ba986cdba..fd78c8e90 100644 --- a/tns-core-modules/http/http.ts +++ b/tns-core-modules/http/http.ts @@ -33,7 +33,7 @@ export function getJSON(arg: any): Promise { export function getImage(arg: any): Promise { return httpRequest .request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) - .then(responce => responce.content.toImage()); + .then(response => response.content.toImage()); } export function getFile(arg: any, destinationFilePath?: string): Promise { diff --git a/tns-core-modules/ui/image/image-common.ts b/tns-core-modules/ui/image/image-common.ts index 850e5a50d..2f3c4f4d4 100644 --- a/tns-core-modules/ui/image/image-common.ts +++ b/tns-core-modules/ui/image/image-common.ts @@ -1,9 +1,8 @@ import { Image as ImageDefinition, Stretch } from "."; -import { View, Property, InheritedCssProperty, Length, Style, Color, isIOS, booleanConverter, CSSType } from "../core/view"; +import { View, Property, InheritedCssProperty, Length, Style, Color, isIOS, booleanConverter, CSSType, traceEnabled, traceWrite, traceCategories } from "../core/view"; import { ImageAsset } from "../../image-asset"; import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source"; import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils"; - export * from "../core/view"; export { ImageSource, ImageAsset, fromAsset, fromNativeSource, fromUrl, isDataURI, isFileOrResourcePath, RESOURCE_PREFIX }; @@ -83,6 +82,15 @@ export abstract class ImageBase extends View implements ImageDefinition { this.imageSource = r; this.isLoading = false; } + }, err => { + // catch: Response content may not be converted to an Image + this.isLoading = false; + if (traceEnabled()) { + if (typeof err === "object" && err.message) { + err = err.message; + } + traceWrite(err, traceCategories.Debug); + } }); } } else if (value instanceof ImageSource) {