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

Fix(nodejs/event_dispatcher): update error/resp handlers #123

Merged
merged 6 commits into from Jun 25, 2018

Conversation

tylerbrandt
Copy link
Contributor

@tylerbrandt tylerbrandt commented Jun 22, 2018

  • (nodejs) Prevent crash when http/https emits an error by adding an 'error' listener
  • (nodejs) Fix requestCallback to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the http.IncomingMessage, and not called in the event of an error (as expected by Optimizely#_sendImpressionEvent/Optimizely#track).

Tested that this version (as 2.1.2-0) does emit the messages expected in the demo app.

Fixes #122
Fixes #124

@@ -98,5 +98,18 @@ describe('lib/plugins/event_dispatcher/node', function() {
eventDispatcher.dispatchEvent(eventObj, callback);
});
});

it('calls callback with err when one is emitted', function(done) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: before changing the event_dispatcher code, the .dispatchEvent call did indeed throw an error.

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to handle the err on the caller here: https://github.com/optimizely/javascript-sdk/blob/master/packages/optimizely-sdk/lib/optimizely/index.js#L192

And log the fact that and error occurred. Otherwise the SDK is going to pretend the call was successful

@tylerbrandt tylerbrandt changed the title Fix(nodejs): add handler for http error event Fix(nodejs/event_dispathcher): update handlers Jun 22, 2018
@tylerbrandt tylerbrandt changed the title Fix(nodejs/event_dispathcher): update handlers Fix(nodejs/event_dispatcher): update handlers Jun 22, 2018
@tylerbrandt tylerbrandt changed the title Fix(nodejs/event_dispatcher): update handlers Fix(event_dispatcher): update handlers Jun 22, 2018
Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it

@tylerbrandt tylerbrandt changed the title Fix(event_dispatcher): update handlers Fix(nodejs/event_dispatcher): update error/resp handlers Jun 22, 2018
@tylerbrandt tylerbrandt merged commit 6d6bb24 into master Jun 25, 2018
@tylerbrandt tylerbrandt deleted the tyler/trap-event-dispatcher-err branch June 25, 2018 18:07
tylerbrandt pushed a commit that referenced this pull request Jun 25, 2018
- (nodejs) Prevent crash when `http`/`https` emits an error by adding an 'error' listener
- (nodejs) Fix `requestCallback` to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the `http.IncomingMessage`, and _not_ called in the event of an error (as expected by `Optimizely#_sendImpressionEvent`/`Optimizely#track`).

Tested that this version (as 2.1.2-0) _does_ emit the messages expected in the demo app.

Fixes #122
Fixes #124
tylerbrandt pushed a commit that referenced this pull request Jun 25, 2018
- (nodejs) Prevent crash when `http`/`https` emits an error by adding an 'error' listener
- (nodejs) Fix `requestCallback` to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the `http.IncomingMessage`, and _not_ called in the event of an error (as expected by `Optimizely#_sendImpressionEvent`/`Optimizely#track`).

Tested that this version (as 2.1.2-0) _does_ emit the messages expected in the demo app.

Fixes #122
Fixes #124
tylerbrandt pushed a commit that referenced this pull request Jun 25, 2018
- (nodejs) Prevent crash when `http`/`https` emits an error by adding an 'error' listener
- (nodejs) Fix `requestCallback` to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the `http.IncomingMessage`, and _not_ called in the event of an error (as expected by `Optimizely#_sendImpressionEvent`/`Optimizely#track`).

Tested that this version (as 2.1.2-0) _does_ emit the messages expected in the demo app.

Fixes #122
Fixes #124
# Conflicts:
#	packages/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js
#	packages/optimizely-sdk/lib/plugins/event_dispatcher/index.node.tests.js
tylerbrandt pushed a commit that referenced this pull request Jun 25, 2018
* Fix(nodejs/event_dispatcher): update error/resp handlers (#123)

- (nodejs) Prevent crash when `http`/`https` emits an error by adding an 'error' listener
- (nodejs) Fix `requestCallback` to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the `http.IncomingMessage`, and _not_ called in the event of an error (as expected by `Optimizely#_sendImpressionEvent`/`Optimizely#track`).

Tested that this version (as 2.1.2-0) _does_ emit the messages expected in the demo app.

Fixes #122
Fixes #124
tylerbrandt pushed a commit that referenced this pull request Jun 25, 2018
* Fix(nodejs/event_dispatcher): update error/resp handlers (#123)

- (nodejs) Prevent crash when `http`/`https` emits an error by adding an 'error' listener
- (nodejs) Fix `requestCallback` to conform to its role as a 'response' listener; notably, ensure it is called when the first argument is interpeted as the `http.IncomingMessage`, and _not_ called in the event of an error (as expected by `Optimizely#_sendImpressionEvent`/`Optimizely#track`).

Tested that this version (as 2.1.2-0) _does_ emit the messages expected in the demo app.

Fixes #122
Fixes #124
@raju-opti raju-opti mentioned this pull request Aug 25, 2023
@raju-opti raju-opti mentioned this pull request Sep 29, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants