Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Oauth client returns socket hangup errrors because the url is hardcoded #71

@j9recurses

Description

@j9recurses

I was trying to use the oauth client like this in a client library I wrote :
module.exports = {
createClient: function (opts) {
opts.url = opts.url || 'http://127.0.0.1:9000'
// This creates an instance of the oauth client,
// which will handle all HTTP communication with your API
var myOauthClient = oauthClient.createClient(opts)
myOauthClient.getThings = myOauthClient.get.bind(myOauthClient, '/things')
return myOauthClient
}
}

Important to note, I am using port 9000 instead of 8080 for my api.

And then, I wanted to use the the client library like this in an app:
client.getThings(function (err, things) {
if (err) {
console.error(err)
} else {
console.log('Things collection has these items:')
console.log(prettyjson.render(things))
}
}

Everyt ime I ran the app, I got this error:
{ Error: socket hang up
at createHangUpError (_http_client.js:250:15)
at Socket.socketOnEnd (_http_client.js:342:23)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) code: 'ECONNRESET', body: {} }

Then I went into oauth-client.js file of this library and noticed that actual url is hardcoded in the client object like this:

this._authClient = restify.createJsonClient({
url: 'http://localhost:8080'
});

This seems weird/not right. This line was causing me to get socket hang up errors.

I changed the line above to this:
this._authClient = restify.createJsonClient({
url: options.url
})

And now everything thing is working. I'd enter a pull request for this change, but I obviously don't have permissions to to create branches, etc.

Can someone please fix this to save others from having to deal with this bug in the future?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions