Skip to content

Object #<Object> has no method 'request' #1

Closed
warpr opened this Issue Nov 20, 2012 · 9 comments

2 participants

@warpr
warpr commented Nov 20, 2012

When trying to use this in Mashery's I/O Docs I see the following error:

TypeError: Object # has no method 'request'
at /home/warp/code/iodocs/node_modules/follow-redirects/index.js:60:40
at unsecuredCall (/home/warp/code/iodocs/app.js:568:23)
at processRequest (/home/warp/code/iodocs/app.js:481:9)
at callbacks (/home/warp/code/iodocs/node_modules/express/lib/router/index.js:272:11)

etc...

https://github.com/warpr/iodocs/blob/coverartarchive/app.js#L564

Do you have any idea if this Is a bug, or am I doing something wrong?

@olalonde
Owner

It shouldn't happen and I don't see anything wrong with your code so far. I'll take a look tomorrow.

@olalonde
Owner

Which version of Node.js are you using? I have only tested on v0.8.11. The error seems to say your native http module doesn't have the request method which is weird.

@warpr
warpr commented Nov 21, 2012

I was using the version shipped by Ubuntu 12.04 (node v0.6.12). I have now installed 0.8.14, and the same problem occurs there.

@olalonde
Owner

Do you get that error if you run the file test/index.js from the repository?

@warpr
warpr commented Nov 28, 2012

Sorry for the late reply. No, test/index.js runs fine. the problem only occurs when "http.request" is assigned to a variable, so this doesn't work:

var foo = http.request;
var req = foo(options, function () {});

And I don't know enough javascript to really understand what is going wrong here. I've created a small test case to illustrate the problem, here is a full transcript: https://gist.github.com/4163907

@olalonde
Owner

Ah I get it. Does it work with the native http module? The problem is that when you assign http.request to foo, the this inside the function is not bound to http anymore. For now, you could do:

var foo = http.request.bind(http);
var req = foo(options, function () {});

If your code sample works with the native http module however, I will have to fix my version too.

@warpr
warpr commented Nov 29, 2012

Yes, it works with the native http module. The .bind() trick sounds like a good workaround for now, thanks!

@olalonde olalonde closed this in 60842d8 Nov 29, 2012
@olalonde
Owner

Hey @warpr thanks a lot for reporting this bug. I think I have fixed it but it would be great if you could confirm.

@warpr
warpr commented Nov 29, 2012

yes, it works now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.