Exceptions in Jovo


#1

Hello everyone!

Is there a way for Jovo to capture exceptions?

That is, if for example an error occurs during an interaction, is there a “try & catch” that makes a voice message such as “Sorry, this feature is not available at the moment”?

Thank you very much in advance!


#2

There might be a better solution built right into JOVO but you can try using .toIntent('YourUnhandledIntent') if you catch an error.

try {
        // Something
    }
    catch (error) {
        return this.toIntent('YourErrorMessageIntent')
    }

You can then define a YourErrorMessageIntent handler which will return your error message text.


#3

Thank you so much for answering @Marko_Arezina

Greetings,

Alberto.


#4

A “global catch” can be handled in ON_ERROR()

 ON_ERROR() {
        let error = this.$handleRequest.error;
        this.tell('Something went wrong');
    }


#5

Hi @AlexSwe,

I added that code under the last Intent in app.setHandler but when an error occurs I don’t get the defined error. The error appears as before.

I don’t know if I’m doing something wrong.

Greetings!


#6

Can someone help me, please?


#7

So you jump into ON_ERROR but this.$handleRequest.error is empty?


#8

This does not go to ON_ERROR:

LAUNCH() {
     throw "test";
},
ON_ERROR() {
      console.log("got error");
}

This is what gets logged:

 Message:

unhandledRejection
{}
TypeError: Cannot read property ‘indexOf’ of undefined
at Function.printError (G:\0DEVELOPMENT\TFS\Test\Blurt\jovo\retirement\node_modules.pnpm\[email protected]\node_modules\jovo-core\src\errors\JovoError.ts:29:19)
at App.handle (G:\0DEVELOPMENT\TFS\Test\Blurt\jovo\retirement\node_modules.pnpm\[email protected]\node_modules\jovo-core\src\core\BaseApp.ts:293:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5)


#9

Hey @vguruv

basic expressions are not supported. ON_ERROR listens to objects type of Error. This should work:

LAUNCH() {
    throw new Error("test");
},
ON_ERROR() {
     console.log("got error");
}