jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

$http.get leading to "TypeError: Cannot read property 'callback' of undefined" #27

Closed PaddyMann closed 9 years ago

PaddyMann commented 9 years ago

Apologies in advance if I'm doing something stupid...

Been using http-batch for a while with no issues. Most of my calls to the server go through $resource and that seems to be working fine.

I need to make a call using $http as part of a validator, and for some reason I get:

angular.js:11782 TypeError: Cannot read property 'callback' of undefined
    at angular-http-batch.js:585

My code is as simple as it gets...:

http.get('http://myUrl...').then(function (data) { ... });

So not sure what's causing the issue. I also had the issue in 1.6.0 before upgrading to latest this morning.

I also tried disabled httpBatcher for this call, but setting httpBatcher.enabled = false; before making the call had no effect.

jonsamwell commented 9 years ago

Hi @PaddyMann!

The call stack would indicate that the batch adapter is not finding the correct request for the returned response. Which version of the library are you using? Are there $resource calls going in with this request as well?

If you could put a breakpoint here and just check that the request object always have a value?

https://github.com/jonsamwell/angular-http-batcher/blob/master/dist/angular-http-batch.js#L501

Also you would need to set enabled false in the httpBatch config object to disable it see https://github.com/jonsamwell/angular-http-batcher/issues/13#issuecomment-106630711

jonsamwell commented 9 years ago

@PaddyMann Also could you give me the raw http request and response I can debug it that way if all else fails :-)

Also what version of angular are you using?

PaddyMann commented 9 years ago

Hej @jonsamwell

Thanks for the speedy response, and apologies - looks like an issue at my end! I've hand-cranked the batch handling on a PHP framework and it's not working for my validation routes...

Sorry for the distraction to your morning :)

On an aside, I see you've adding support for node and Facebook adapters. What are the best links to read more about these specs? https://developers.facebook.com/docs/graph-api/making-multiple-requests for Facebook? Is the Facebook one gaining traction as a wider standard? :)

jonsamwell commented 9 years ago

Hey @PaddyMann

No worries at all! Yes the node ones are gaining traction and I've had a few requests for being able to batch to facebook. I'm currently still developing that one but shouldn't be too long.

The Facebook one is very much like the approach many of the batching libraries in node take. Basically creating a http post and putting all the information of each request in a json object rather than the complicated approach the http batching spec takes with multipart boundaries.

Yes I use the like you reference above as the spec for the Facebook adapter.

PaddyMann commented 9 years ago

nice - looks much simpler :)

Thanks!