FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(image): uncaught error in promise with image handling by NathanWalker · Pull Request #6453 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function ensureImageSource() {
export function request(options: http.HttpRequestOptions): Promise<http.HttpResponse> {
return new Promise<http.HttpResponse>((resolve, reject) => {

if (!options.url) {
reject(new Error("Request url was empty."));
return;
}

try {
var network = domainDebugger.getNetwork();
var debugRequest = network && network.create();
Expand Down
15 changes: 12 additions & 3 deletions tns-core-modules/http/http.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ export function getJSON<T>(arg: any): Promise<T> {
}

export function getImage(arg: any): Promise<ImageSource> {
return httpRequest
.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg)
.then(response => response.content.toImage());
return new Promise<any>((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<any> {
Expand Down

Back | FazBrowse Home | New Git URL