Skip to content

Commit

Permalink
Merge 3b0485b into a63faa1
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlozier committed Sep 30, 2019
2 parents a63faa1 + 3b0485b commit 61fcce3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class ApiClient {
wrapCallback(httpMethod, callback = () => null) {
return (err, res) => {
const expectedContentType = (this.isEncrypted) ? "application/jose+json" : "application/json";
const invalidContentType = res && res.header && res.status !== 204 && res.header["content-type"].indexOf(expectedContentType) === -1;
const invalidContentType = res && res.header && res.header["content-type"] && res.header["content-type"].indexOf(expectedContentType) === -1;
if (invalidContentType) {
callback([{
message: "Invalid Content-Type specified in Response Header",
Expand Down
25 changes: 25 additions & 0 deletions test/utils/ApiClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,5 +1168,30 @@ describe("utils/ApiClient", () => {
});
callback(undefined, rawRes);
});

it("should call callback with COMMUNICATION_ERROR if status is 429", (cb) => {
const client = new ApiClient("test-username", "test-password", "test-server");

const rawRes = {
body: "test",
status: 429,
header: {},
};

const rawErr = {
status: 429,
};

const callback = client.wrapCallback("POST", (err, body, res) => {
body.should.be.equal("test");
rawRes.should.be.deep.equal(res);
err.should.be.deep.equal([{
message: "Could not communicate with test-server",
code: "COMMUNICATION_ERROR",
}]);
cb();
});
callback(rawErr, rawRes);
});
});
});

0 comments on commit 61fcce3

Please sign in to comment.