Search code examples
javascriptapiangularjsstatusnet

API posts to StatusNet using AngularJS - 200 OK throws $http's error function


The basic problem here is that an empty 200 OK triggers the error function instead of the success function. The API forces a content type (JSON or XML) that the $http object automatically attempts to parse. Both require a root object to parse successfully, so the $http object throws the error response instead of the success. The error function also doesn't include the status code (it's in the object but always set to 0 regardless of the actual response code; same with the error value), so I need some way to inject code before/during the parsing step to make it succeed on an empty 200 response.


Solution

  • The short answer here is that I can't, because the POSTs are cross-site. The contents are intentionally empty, but would appear empty regardless because of the way cross-site posting works. This is also the reason no status code is available which is what causes the error branch to be hit regardless of any attempts to manipulate the results via transformResponse.