From f7ee2bdbde9b85c84483efb7e3fd755446d38c72 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Wed, 24 Oct 2018 13:58:20 -0700 Subject: [PATCH 1/3] fix(image): uncaught error in promise with image handling --- .../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 2055b09ebf..acb9d2335e 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('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 fd78c8e90c..251aa7c002 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 { From 83f249c63f32f6678482923da99765b0f55ac895 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 12 Nov 2018 19:40:05 -0800 Subject: [PATCH 2/3] . --- tns-core-modules/http/http-request/http-request.ios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 acb9d2335e..c4722e466c 100644 --- a/tns-core-modules/http/http-request/http-request.ios.ts +++ b/tns-core-modules/http/http-request/http-request.ios.ts @@ -70,7 +70,7 @@ export function request(options: http.HttpRequestOptions): Promise((resolve, reject) => { if (!options.url) { - reject('Request url was empty.'); + reject(new Error('Request url was empty.')); return; } From ff18645dd6119b8b8d8a0fff5e399b50725c2706 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Tue, 13 Nov 2018 09:02:49 +0200 Subject: [PATCH 3/3] fix: tslint error --- tns-core-modules/http/http-request/http-request.ios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c4722e466c..5b9b6716da 100644 --- a/tns-core-modules/http/http-request/http-request.ios.ts +++ b/tns-core-modules/http/http-request/http-request.ios.ts @@ -70,7 +70,7 @@ export function request(options: http.HttpRequestOptions): Promise((resolve, reject) => { if (!options.url) { - reject(new Error('Request url was empty.')); + reject(new Error("Request url was empty.")); return; }