This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
1.4.5 $http transformResponse property isn't fired when status code is 204 (No Content) #12976
Closed
Description
I keep wanting to use the transform response property of the config object with an http service wrapper. The docs claim that the transformResponse is fired when there is a successful status message. Instead, I get no transformResponse firing.
I have tests that show OK, 200, works, but 204 with null or undefined data does not.
The reason why is I'd like to set up default data, but I cannot with this current behavior (I took out a few things, but this should get the gist:
describe("When using the SubNavServiceUri", function() {
var serviceUri;
var requestUri = "/api/aliens";
var collection = null;
var httpBackend;
beforeEach(function () {
module("superSiteApp");
inject(function (_$httpBackend_, _SubNavServiceUri_) {
httpBackend = _$httpBackend_;
serviceUri = _SubNavServiceUri_;
});
});
afterEach(function () {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
});
it("and NoContent it should return empty collection", function () {
// set up correct end point
httpBackend
.expectGET(requestUri)
.respond(HttpStatusCode.NoContent);
var actual;
serviceUri.get(requestUri).then(function (result) {
actual = result.data;
});
httpBackend.flush();
expect([]).toEqual(actual);
expect(0).toEqual(actual.length);
});
...
service("SubNavServiceUri", ["$http", function ($http) {
var isNullOrUndefined = function(item) {
return item === null || item === undefined;
};
var transformData = function(data) {
var result = [];
return result;
};
var get = function(uri) {
var object = {
cache: false,
transformResponse: function (data, headersGetter, status) {
console.log("howdy ");
console.log("headersGetter " + headersGetter);
console.log("status " + status);
if (isNullOrUndefined(data)) {
return [];
} else {
return transformData(data);
}
}
};
return $http.get(uri, object);
};
return {
"get": get
};
...