Error Handling

Errors can happen, and so by including an error handler in your response processing we can ensure that users are always informed.

If an input is invalid, or another error is caught, the responseBuilder can return a functionFailure,

/**
 * BlockPointer containing block id found in IntelAgent
 */
const errorBlock: BlockPointer = {
  id: '60db2d02d19a13bc109c5bd4'
};

/**
 * Function failure params used to handle errors, for example in the case of bad data
 */
const failureParams: FunctionFailureParams = {
  errorBP: errorBlock,
  resetForm : true,
  tryAgain : true
};

responseBuilder.functionFailure(failureParams);

The failureParams object is a particular type used to indicate how to handle the error. It contains an error BlockPointer, pointing to a block with an error message, as well as two optional fields, resetForm and tryAgain, defaulting to true.

resetForm indicates that the form should be unset, similarly to the unsetFunctionForm function

tryAgain offers a button to try again if true

For example, in the division handler, one such case of invalid input, is a divide by zero error. This is a number that cannot be divided by as of yet, so that number is checked early in the function, before further logic.

if (divisionNumber.value === 0) {
    responseBuilder.functionFailure(failureParams);
    return;
}

Last updated