Skip to content

Commit

Permalink
Update user-defined error handling for async and default response res…
Browse files Browse the repository at this point in the history
…olution
  • Loading branch information
ajcrites committed Feb 17, 2017
1 parent 415d62b commit 2a839a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,15 @@ alexa.app = function(name) {
})
.catch(function(e) {
if (typeof self.error == "function") {
return self.error(e, request, response);
// Default behavior of any error handler is to send a response
return Promise.resolve(self.error(e, request, response)).then(function() {
if (!response.resolved) {
response.resolved = true;
return response.send();
}
// propagate successful response if it's already been resolved
return response.response;
});
} else if (typeof e == "string" && self.messages[e]) {
if (!request.isAudioPlayer()) {
response.say(self.messages[e]);
Expand Down
4 changes: 2 additions & 2 deletions test/test_alexa_app_unknown_type_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("Alexa", function() {
it("responds with a spoken message for uncaught errors in the globally defined error function and resolves", function() {
testApp.error = function(e, request, response) {
response.say("Sorry, something bad happened");
response.send();
return response.send();
};

var subject = testApp.request(mockRequest).then(function(response) {
Expand All @@ -78,7 +78,7 @@ describe("Alexa", function() {
it("responds with a spoken message for uncaught errors in the globally defined error function and fails", function() {
testApp.error = function(e, request, response) {
response.say("Sorry, something bad happened");
response.fail(e);
return response.fail(e);
};

var subject = testApp.request(mockRequest).then(function(response) {
Expand Down

0 comments on commit 2a839a3

Please sign in to comment.