mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
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
This commit is contained in:

committed by
Alexander Vakrilov

parent
0c3ecbc57b
commit
5cd8a1fc2a
@ -33,7 +33,7 @@ export function getJSON<T>(arg: any): Promise<T> {
|
|||||||
export function getImage(arg: any): Promise<ImageSource> {
|
export function getImage(arg: any): Promise<ImageSource> {
|
||||||
return httpRequest
|
return httpRequest
|
||||||
.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg)
|
.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<any> {
|
export function getFile(arg: any, destinationFilePath?: string): Promise<any> {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { Image as ImageDefinition, Stretch } from ".";
|
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 { ImageAsset } from "../../image-asset";
|
||||||
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
|
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
|
||||||
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
|
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
|
||||||
|
|
||||||
export * from "../core/view";
|
export * from "../core/view";
|
||||||
export { ImageSource, ImageAsset, fromAsset, fromNativeSource, fromUrl, isDataURI, isFileOrResourcePath, RESOURCE_PREFIX };
|
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.imageSource = r;
|
||||||
this.isLoading = false;
|
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) {
|
} else if (value instanceof ImageSource) {
|
||||||
|
Reference in New Issue
Block a user