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

http toString will raise error if response cannot be converted to string by enchev · Pull Request #1089 · 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
2 changes: 1 addition & 1 deletion apps/tests/http-tests.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 @@ -53,7 +53,7 @@ export var test_getString_fail = function (done) {
export var test_getString_fail_when_result_is_not_string = function (done) {
var result;

http.getJSON({ url: "https://httpbin.org/image/png", method: "GET" }).catch(function (e) {
http.getString({ url: "https://httpbin.org/image/png", method: "GET" }).catch(function (e) {
result = e;
try {
TKUnit.assert(result instanceof Error, "Result from getString().catch() should be Error! Current type is " + typeof result);
Expand Down
8 changes: 7 additions & 1 deletion http/http-request.android.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 @@ -45,7 +45,13 @@ function onRequestComplete(requestId: number, result: com.tns.Async.Http.Request
callbacks.resolveCallback({
content: {
raw: result.raw,
toString: () => { return result.responseAsString; },
toString: () => {
if (types.isString(result.responseAsString)) {
return result.responseAsString;
} else {
throw new Error("Response content may not be converted to string");
}
},
toJSON: () => { return utils.parseJSON(result.responseAsString); },
toImage: () => {
return new Promise<imageSource.ImageSource>((resolveImage, rejectImage) => {
Expand Down

Back | FazBrowse Home | New Git URL