Skip to content

Commit

Permalink
Return a promise from handleRequest when the request handler itself i…
Browse files Browse the repository at this point in the history
…s a promise
  • Loading branch information
Stephen D'Olier committed Sep 28, 2017
1 parent 91e0dc5 commit b513722
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions assistant-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ class AssistantApp {
debug('handleRequest: handler=%s', handler);
if (!handler) {
this.handleError_('request handler can NOT be empty.');
return;
return false;
}
if (typeof handler === 'function') {
debug('handleRequest: function');
// simple function handler
this.handler_ = handler;
const promise = handler(this);
if (promise instanceof Promise) {
promise.then(
return promise.then(
(result) => {
debug(result);
})
Expand All @@ -534,17 +534,17 @@ class AssistantApp {
});
} else {
// Handle functions
return;
return true;
}
return;
return false;
} else if (handler instanceof Map) {
debug('handleRequest: map');
const intent = this.getIntent();
const result = this.invokeIntentHandler_(handler, intent);
if (!result) {
this.tell(!this.lastErrorMessage_ ? ERROR_MESSAGE : this.lastErrorMessage_);
}
return;
return result;
}
// Could not handle intent
this.handleError_('invalid intent handler type: ' + (typeof handler));
Expand Down Expand Up @@ -1707,7 +1707,7 @@ class AssistantApp {
debug('map of intents');
const promise = value(this);
if (promise instanceof Promise) {
promise.then(
return promise.then(
(result) => {
// No-op
})
Expand Down

0 comments on commit b513722

Please sign in to comment.