-2

I keep getting error

error Each then() should return a value or throw

I'm not sure how to fix it. I'm trying to use this for smart home and typed this in index.js, but received an error and could not deploy the firebase.

Please help me on how to fix this.

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp();

const DialogflowApp = require('actions-on-google').DialogflowApp;

exports.receiveAssistantRequests = functions.https.onRequest((request, response) => {

const app = new DialogflowApp({request: request, response: response});

function handlerRequest(app) {

    const device = app.getArgument('devices');
    const status = app.getArgument('status');

    return admin.database().ref(`/automation/${device}/value`).set(status)
        .then(snapshot => { //I believe this is where the error is..
            app.ask(`Ok, switching ${device} ${status}. Do you want to control anything else?`);
        });

}
app.handleRequest(handlerRequest);
});
rene
  • 41,474
  • 78
  • 114
  • 152
  • Just a wild guess, but maybe the problem is that. each then() should return a value or throw. Read that error carefully. Then read it again. If you still don't get it, keep reading it until you do. Then, look at your code. See if "each then() returns a value or throws". Does it? –  Aug 05 '18 at 11:35

1 Answers1

1

You should return in side each .then

  .then(snapshot => { //I believe this is where the error is..
            return app.ask(`Ok, switching ${device} ${status}. Do you want to control anything else?`);
        });
JustKhit
  • 407
  • 3
  • 9