Why does the POST 204 response (without content) call the Angularjs error function?

I have an Angularjs application that uses $http.post() to make web service calls. The called method has a void return type and it generates a 204 response code (no content). This is part of the error function, which is defined in the .then() callback and prints "no element found" in the log.

If I return something from the method, it will return a normal 200 response code.

Why does the success code trigger the error function?

Code as requested:

 function myFn(inputData) { var d = { data: inputData }; $http.post("../api/my/serverFn", d) .then( function(response) { $rootScope.AddMsg("Success"); }, function(response) { // The 204 response goes here. $rootScope.AddMsg("Error"); }); } 

Screen shot requested: enter image description here

+5
source share
1 answer

AngularJS does not treat answer 204 as an error. The investigation showed that there was actually an HTTP interceptor on the stack that rejected the promise if the received response had the status 204, turning the successful response into an error.

+5
source

Source: https://habr.com/ru/post/1235718/


All Articles