Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse.Cloud.httpRequest failing with undefined status code (trying to use OpenTok) #904

Closed
astanton opened this issue Mar 7, 2016 · 4 comments

Comments

@astanton
Copy link

astanton commented Mar 7, 2016

I want to preface this with I saw this was posted and there was a fix put in for it #783 , however I am still seeing the problem.

This is the exact issue pasted from the Heroku logs, with the keys and userId's in the parameters modified for obvious reasons:

2016-03-07T23:12:44.841892+00:00 app[web.1]: OpenTok: Error while creating session
2016-03-07T23:12:44.841904+00:00 app[web.1]: Request failed with response code undefined
2016-03-07T23:12:44.841905+00:00 app[web.1]: Raw response: 
2016-03-07T23:12:44.841906+00:00 app[web.1]: undefined
2016-03-07T23:12:44.841906+00:00 app[web.1]: 
2016-03-07T23:12:44.843620+00:00 app[web.1]: OpenTok: Sent the following request: 
2016-03-07T23:12:44.843634+00:00 app[web.1]: {"url":"https://api.opentok.com/hl/session/create","method":"POST","headers":{"X-TB-PARTNER-AUTH":"key:secret"},"body":{"userIdForConnection":"xxx","userId":"yyy","location_hint":"localhost"},"followRedirect":false}
2016-03-07T23:12:44.843636+00:00 app[web.1]: 
2016-03-07T23:12:44.861257+00:00 app[web.1]: /app/node_modules/parse-server/lib/index.js:288
2016-03-07T23:12:44.873516+00:00 app[web.1]:       throw err;
2016-03-07T23:12:44.873578+00:00 app[web.1]: 
2016-03-07T23:12:44.873592+00:00 app[web.1]: TypeError: first argument must be a string or Buffer
2016-03-07T23:12:44.873594+00:00 app[web.1]:     at ClientRequest.OutgoingMessage.write (_http_outgoing.js:443:11)
2016-03-07T23:12:44.873595+00:00 app[web.1]:     at Request.write (/app/node_modules/request/request.js:1371:25)
2016-03-07T23:12:44.873595+00:00 app[web.1]:     at end (/app/node_modules/request/request.js:561:16)
2016-03-07T23:12:44.873608+00:00 app[web.1]:     at processImmediate [as _immediateCallback] (timers.js:383:17)
2016-03-07T23:12:44.914729+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-03-07T23:12:44.914981+00:00 app[web.1]: npm ERR! node v5.7.1
2016-03-07T23:12:44.916121+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-03-07T23:12:44.917253+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the parse-server-example package,
2016-03-07T23:12:44.917446+00:00 app[web.1]: npm ERR! not with npm itself.
2016-03-07T23:12:44.917633+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-03-07T23:12:44.917998+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-03-07T23:12:44.929197+00:00 app[web.1]: 
2016-03-07T23:12:44.929651+00:00 app[web.1]: npm ERR!     /app/npm-debug.log

As with the other issue, this is the call from opentok.js that is making the call

OpenTokSDK.prototype.apiRequest = function(endpoint, authScheme, options, cb) {

  // options is optional
  if (cb === undefined) { cb = options; options = {}; }

  var requestOptions = {
    url: urlFromEndpoint(endpoint, options.endpoint),
    method: methodFromEndpoint(endpoint),
    headers: {},
    body: options.data || {},
    success: function(response) {
      cb(null, response);
    },
    error: function(response) {
      cb(new Error("Request failed with response code " + response.status + "\n" +
                   "Raw response: \n" + response.text + "\n"));
    }
  };

  if (authScheme === AUTH.PARTNER) {
    requestOptions.headers[authScheme] = this.apiKey + ':' + this.apiSecret;
  } else if (authScheme === AUTH.TOKEN) {
    requestOptions.headers[authScheme] = this.generateToken.apply( this, options.auth );
  } else {
    console.warn("OpenTok: No known authentication scheme chosen for the following request: \n" +
      JSON.stringify(requestOptions) + "\n");
  }

  Parse.Cloud.httpRequest(requestOptions);
  console.log("OpenTok: Sent the following request: \n" + JSON.stringify(requestOptions) + "\n");
  return;
};

I have narrowed it down to that Parse.cloud.httpRequest(requestOptions) that is causing this issue.

You can also see what the actual request was being made in the Heroku logs. I also want to mention that when I hit that endpoint in CURL with the actual key:secret, it actually comes back with a 200 and no errors. So I am not sure why this is even erroring in the first place.

I also have updated my parse-server on Heroku with the latest code as of 30 minutes ago, so it has the code that fixed #783 in there, and I've verified it by looking at the file on my Heroku server.

Any ideas? Is this an issue with the 'request node' module that is required inside of the httpRequest.js?

@astanton
Copy link
Author

astanton commented Mar 9, 2016

Any ideas? It seems that this was originally an issue in the node module request but they fixed it here:

request/request#1904

But I'm still getting the issue, although my number lines are a little bit different.

@astanton
Copy link
Author

astanton commented Mar 9, 2016

Figured it out finally.

If anyone else runs into this problem, I had to just run JSON.stringify() on the request.body param that was being passed into Parse.Cloud.httpRequest method.

It doesn't like Objects and needs a string or Buffer type, and I have no clue why it worked fine on Parse.com hosted parser-server without making this change, but I had to change it on the one hosted on Heroku and now it's working fine.

@astanton astanton closed this as completed Mar 9, 2016
@flovilmart
Copy link
Contributor

You can set the content-type header to application/json

@astanton
Copy link
Author

astanton commented Mar 9, 2016

Thanks I will give that a try tonight instead of my solution, so that I don't have to modify the file that I had to modify, since it was a third party library. I can set that header higher up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants