mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #1089 from NativeScript/http-toString
http toString will raise error if response cannot be converted to string
This commit is contained in:
@ -53,7 +53,7 @@ export var test_getString_fail = function (done) {
|
|||||||
export var test_getString_fail_when_result_is_not_string = function (done) {
|
export var test_getString_fail_when_result_is_not_string = function (done) {
|
||||||
var result;
|
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;
|
result = e;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result instanceof Error, "Result from getString().catch() should be Error! Current type is " + typeof result);
|
TKUnit.assert(result instanceof Error, "Result from getString().catch() should be Error! Current type is " + typeof result);
|
||||||
|
@ -45,7 +45,13 @@ function onRequestComplete(requestId: number, result: com.tns.Async.Http.Request
|
|||||||
callbacks.resolveCallback({
|
callbacks.resolveCallback({
|
||||||
content: {
|
content: {
|
||||||
raw: result.raw,
|
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); },
|
toJSON: () => { return utils.parseJSON(result.responseAsString); },
|
||||||
toImage: () => {
|
toImage: () => {
|
||||||
return new Promise<imageSource.ImageSource>((resolveImage, rejectImage) => {
|
return new Promise<imageSource.ImageSource>((resolveImage, rejectImage) => {
|
||||||
|
Reference in New Issue
Block a user