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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/services/DomainRobotService.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ class DomainRobotService {
{
method,
url: encodeURI(url),
data
// Only attach `data` when the caller actually provided a body.
// Leaving `data` as its `null` default still makes axios
// serialize it into a literal "null" body (given the forced
// Content-Type: application/json default below), which breaks
// GET requests against APIs that reject a body on GET or that
// strictly parse the JSON body as an object/array.
...(data !== null ? { data } : {})
},
this.axiosconfig
);
Expand Down Expand Up @@ -148,8 +154,8 @@ class DomainRobotService {
}
}

async sendGetRequest(url) {
return this.sendRequest("GET", url);
async sendGetRequest(url, data = null) {
return this.sendRequest("GET", url, data);
}

async sendPostRequest(url, data) {
Expand Down
9 changes: 4 additions & 5 deletions tests/Integration/DomainService.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ describe("DomainService HTTP (integration)", () => {

expect(lastRequest.method).to.be.equal("POST");
expect(lastRequest.url).to.be.equal("/domain/example.com/_authinfo1");
// No payload is passed, so sendRequest falls back to its `data = null`
// default. With the global application/json Content-Type axios
// serializes that to the JSON literal "null" (same behaviour in 0.x and
// 1.x - not an upgrade regression).
expect(lastRequest.body).to.be.equal("null");
// No payload is passed, so `data` stays at its `null` default and
// sendRequest omits the `data` field from the axios request options
// entirely, instead of sending a literal "null" JSON body.
expect(lastRequest.body).to.be.equal("");

expect(result.status).to.be.equal(200);
});
Expand Down
Loading