The onError method is added to properly handle errors, either with the platform or with the developers' Apps.
The onError method is executed automatically when there is an error in the error stack of the state Object.
Errors can be added to the stack during the Intent Validation process or during the Intent Resolution process as shown below:
if (errorCondition1) {
state.addErrorToStack(1001, 'Error message 1')
}
if (errorCondition2) {
state.addErrorToStack(1002, 'Error message 2')
}
if (errorCondition3) {
state.addErrorToStack(1003, 'Error message 3')
}
If multiple errors happen throughout the runtime, they will be added to the error stack.
The addErrorToStack method takes a code and a message as parameters and generates an Error Object.
The onError method processes the error messages and displays them in a way that is more user friendly.
The example below shows the raw stack to the user:
publishAppForTest.onError = () => {
this._.forEach(this.errorStack, error => {
state.addStringResponse(error.errorMessage)
});
};
The example below displays a business logic error in a way that is more user friendly:
publishAppForTest.onError = () => {
this._.forEach(this.errorStack, error => {
if (error.errorCode === 5) {
state.addStringResponse('I am having problems Processing your request, but don't worry, my developers have already been notified')
} else {
state.addStringResponse(error.errorMessage)
});
};
Error number 5 is a logic error that may occur during the Intent Resolution Process.
Comments
0 comments
Please sign in to leave a comment.