alexa-app icon indicating copy to clipboard operation
alexa-app copied to clipboard

alexaApp.pre fail not working as I'd expect

Open cpup22 opened this issue 9 years ago • 8 comments

So i want to do a check to see if AccountLinking is setup okay in every pre check and if it's not, return a link card to as the user to setup.

But when I do the following:

res.linkAccount();
       res.say("Looks like you need to link your account. Please open the Alexa app for setup.");
      response.fail("Account not linked");

it fails completely without sending the linkAccount card or saying my message. If I comment out response.fail it works in that i see my link card and hear my message BUT it goes onto the next step whereas I'd like to return to the user rather than passing them onto the intent.

Is this just something I'm doing wrong?

cpup22 avatar Dec 27 '16 14:12 cpup22

Without looking at the code I am going to guess it's a bug. We probably clear the response incorrectly in this case. Maybe try to write a test for this first, it should be fairly easy to fix.

dblock avatar Dec 28 '16 14:12 dblock

@cpup22 Did you have better luck with the latest on HEAD (next 2.4.0 release)? Maybe try to build your scenario is a mocha test here?

dblock avatar Feb 05 '17 14:02 dblock

I haven't tested again. I switched back from app-server to alexa-app only to try to pass certification. I changed my code to move back to alexa-app. I need to rebuilt the server environment again to test.

cpup22 avatar Feb 05 '17 14:02 cpup22

Am also having the same problem here. After doing a return response.linkAccount() from pre() The request still gets passed onto the intent

koyinusa avatar Jun 21 '17 16:06 koyinusa

Please double check that you have the latest version and try to write a test for this, I am pretty sure it works as expected @koyinusa.

dblock avatar Jun 21 '17 17:06 dblock

hmm.. what i use is

    response.linkAccount();
    throw new Error('Account Not Linked');

then my error handler looks like:

    app.error = (exception, request, response) => {
        const msg = exception.toString();
        if (msg === 'Error: Account Not Linked') {
            response.say('You need to link your account, please open the Alexa app to proceed.');
        } else {
            console.warn('Encountered error: ', msg);
        }
    }

am I doing it wrong?

ericblade avatar Jun 24 '17 05:06 ericblade

@dblock I got it working by calling send. So my final working code looks like

response.linkAccount()
return response.say(statement).send()

You can also try this @ericblade. Instead of failing abruptly. You might instead return a statement that tells the user what they need to do, which in this case is to link their account

koyinusa avatar Jun 24 '17 06:06 koyinusa

yeah.. it might make more sense if i threw the error, then responded in the error handler with both actions, instead of doing one of the actions above, then throwing the error, then responding with the other action... when i wrote that, life was insane, and i was barely able to think :-D

OTOH, even calling it an "Error" is kind of misleading, too. Usually I would treat Errors as more fatal .. but for some reason I decided to use it as a signaling mechanism there...

ericblade avatar Jun 25 '17 23:06 ericblade