Skip to content

Commit

Permalink
Bug fix for SendRequest without parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalFlow committed Mar 9, 2017
1 parent 46ed3fe commit 7758360
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/js/WebApiClient.Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,22 @@
/// <param name="url" type="String">URL target for request.</param>
/// <param name="payload" type="Object">Payload for request.</param>
/// <param name="requestHeaders" type="Array">Array of headers that consist of objects with key and value property.</param>
/// <returns>Promise for sent request.</returns>
/// <returns>Promise for sent request or result if sync.</returns>
var params = parameters || {};

// Fallback for request headers array as fourth parameter
if (Array.isArray(parameters)) {
parameters = {
headers: parameters
if (Array.isArray(params)) {
params = {
headers: params
};
}

var asynchronous = GetAsync(parameters);
var asynchronous = GetAsync(params);

if (asynchronous) {
return SendAsync(method, url, payload, parameters, previousResponse);
return SendAsync(method, url, payload, params, previousResponse);
} else {
return SendSync(method, url, payload, parameters, previousResponse);
return SendSync(method, url, payload, params, previousResponse);
}
};

Expand Down
11 changes: 11 additions & 0 deletions src/spec/WebApiClientSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,17 @@ describe("WebApiClient", function() {
})
.finally(done);
});

it("should not fail if parameters are ommitted", function(done){
WebApiClient.SendRequest("POST", WebApiClient.GetApiUrl() + "accounts")
.then(function (result) {
expect(result).toBeDefined();
})
.catch(function(error) {
expect(error).toBeUndefined();
})
.finally(done);
});
});

describe("Errors", function() {
Expand Down

0 comments on commit 7758360

Please sign in to comment.