-
Notifications
You must be signed in to change notification settings - Fork 0
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
V1.3.8 handle exception gracefully when a url doesn't resolve #63
Conversation
lib/key.js
Outdated
// handle any uncaught exceptions | ||
.catch((err) => { | ||
|
||
return err.message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be return reject(err);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be return Promise.reject(err)
? I think reject
is outside of the scope..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it this way initially. Unfortunately, the unhandled promise rejection didn't get fixed killing the realtime app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, I could either go with Promise.resolve(err); or just the way it is in order to send a graceful message to the realtime app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a catch for the yield ensureAuthHeaders call here and then if it catches the error emit the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ensureAuthHeaders
fails, the co
should bubble the exception as a rejected Promise. However, notice that the co
function is not being returned... add a return
statement before co
and this will probably help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or rewrite a bit...
self.connect = (socketEventSubscriber) => (co(function *() {
// teh codez herr
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, working on a fix. on the player.js file, thank you.
We found an issue with socket-io-client where it doesn't try to reconnect if failed during during authorization. Craig is looking into whether upgrading socket-io-client is a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/lib/key.js
Outdated
@@ -279,7 +279,7 @@ describe('key', () => { | |||
}); | |||
|
|||
describe('#ensureAuthHeaders', () => { | |||
it('should require clientId', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove the callback here but don't use async
and await
then the test won't run / complete the way it is intended to. If you'd like to head this route, the better step is to upgrade the mocha
dependency, but this is a relatively in-depth task because there may need to be a lot more adjustments made in the SDK to support this.
test/lib/key.js
Outdated
}); | ||
}); | ||
|
||
it('should require secret', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above - this is not having the intended effect, the test is not running.
lib/player.js
Outdated
clientId = authHeaders[CLIENT_ID]; | ||
|
||
socket.io.opts.query = ['clientId=', clientId, '&', 'token=', authToken].join(''); | ||
if(authHeaders != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition will always be true because you are always returning an error from the call to ensureAuthHeaders or it actually returns headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, you would never try to connect at all meaning the reconnect logic won't be hit at all
lib/player.js
Outdated
|
||
err = JSON.parse(err); | ||
if(err.code == 401) { | ||
socket.disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is off here
@brozeph , @cmerchant , @rmomii the same PR with new changes if you could take a look would be great. |
lib/player.js
Outdated
options = {}; | ||
} | ||
|
||
if (validation.isEmpty(socketEventSubscriber) || !socketEventSubscriber.emit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but we're really not checking to see if the socketEventSubscriber is an EventEmitter per se, only that it has a property named emit
and not even that it's a function. Might be worthwhile thinking through how to validate if the emit
is a function as well.
if ([
validation.isEmpty(socketEventSubscriber),
validation.isEmpty(socketEventSubscriber.emit),
typeof socketEventSubscriber.emit !== 'function'
].some((val) => val)) {
throw new Error('socketEventSubscriber must be an instance of event.EventEmitter');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taken care of
lib/player.js
Outdated
clientId = authHeaders[CLIENT_ID]; | ||
|
||
url = [protocol, '://', options.host || settings.host].join(''); | ||
query = ['clientId=', clientId, '&', 'token=', authToken].join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query = ['clientId=', clientId, '&token=', authToken].join('');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taken care of
lib/player.js
Outdated
socket.on('reconnecting', (attempt) => { | ||
let connection = { | ||
'connectionAttempt' : attempt, | ||
'headerReset' : false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is headerReset
used by clients... there is also an isReconnect
that's present on other connection
objects emitted and this field isn't consistent with those. Is this by design and is this well understood by the consuming code? Seems like this could lead to some confusion...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is used by realtime app. It should be documented in the sdk readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main reason is that we are emiting a connected event for both connect and reconnect. It lets the consumer be aware of this situation. In the realtime app case, it is used for logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get rid of headerReset. That seems to be a relic of an earlier implementation. @deepakdahal please double check that before removing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmerchant looks like we have tests added for headerReset https://github.com/PlayNetwork/playnetwork-sdk-nodejs/blob/develop/test/lib/player.js#L216
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are there, but do we actually use it anywhere? If not, we should remove it and the tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, headerReset has been removed both from test and code
authToken = authHeaders[AUTH_TOKEN]; | ||
clientId = authHeaders[CLIENT_ID]; | ||
|
||
url = [protocol, '://', options.host || settings.host].join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it ever be possible that options.host and settings.host are both defined. What would happen in this case in forming the url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.host
should take precedent over settings.host
if this were to be the case... the idea here is that you configure the SDK at initialization, but you have the ability to override on a per call basis for über flexibility
I thought there was some co function that needed a return value. Where is that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close!
lib/player.js
Outdated
validation.isEmpty(socketEventSubscriber), | ||
validation.isEmpty(socketEventSubscriber.emit), | ||
typeof socketEventSubscriber.emit !== 'function' | ||
].some((val) => val)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de-indent the line 😺
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taken care of
lib/player.js
Outdated
socket.on('reconnecting', (attempt) => { | ||
let connection = { | ||
'connectionAttempt' : attempt, | ||
'headerReset' : false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are there, but do we actually use it anywhere? If not, we should remove it and the tests...
@brozeph @cmerchant I should have covered everything :) |
Looks good to me |
Whenever a url doesn't resolve(due to network connectivity, incorrect url etc.), this lib throws an exception which wasn't handled gracefully.