From 950fdcf5e71416d19882d8d61c996651fed976d0 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 13 Nov 2018 08:49:37 -0800 Subject: [PATCH] fix(image): uncaught error in promise with image handling (#6453) --- .../http/http-request/http-request.ios.ts | 5 +++++ tns-core-modules/http/http.ts | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tns-core-modules/http/http-request/http-request.ios.ts b/tns-core-modules/http/http-request/http-request.ios.ts index 2055b09eb..5b9b6716d 100644 --- a/tns-core-modules/http/http-request/http-request.ios.ts +++ b/tns-core-modules/http/http-request/http-request.ios.ts @@ -69,6 +69,11 @@ function ensureImageSource() { export function request(options: http.HttpRequestOptions): Promise { return new Promise((resolve, reject) => { + if (!options.url) { + reject(new Error("Request url was empty.")); + return; + } + try { var network = domainDebugger.getNetwork(); var debugRequest = network && network.create(); diff --git a/tns-core-modules/http/http.ts b/tns-core-modules/http/http.ts index fd78c8e90..251aa7c00 100644 --- a/tns-core-modules/http/http.ts +++ b/tns-core-modules/http/http.ts @@ -31,9 +31,18 @@ export function getJSON(arg: any): Promise { } export function getImage(arg: any): Promise { - return httpRequest - .request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) - .then(response => response.content.toImage()); + return new Promise((resolve, reject) => { + httpRequest.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) + .then(r => { + try { + resolve(r.content.toImage()); + } catch (err) { + reject(err); + } + }, err => { + reject(err); + }); + }); } export function getFile(arg: any, destinationFilePath?: string): Promise {