Skip to content

Widget Error Handling

Widget error handling can be done in several levels.

  1. Throwing errors from plsvc implementation directly using Error_SYS and handling them in widget implementation.

Widget developer can catch these errors and handle them accordingly using the error code (Error_SYS tag). Any other unexpected errors should be suppressed and shown only in the console.

Error_SYS.Appl_General(lu_name_, 'WIDGET_ERROR_QTY: Quantity Cannot be greater than 10!');
catchError((error: any) => {
    const stdError: StandardOdataError | null = this.widgetDataProviderService.getStandardOdataError(error);
    if(stdError) {
        // Here we are showing a toast message for all the standard errors 
        // including errors thrown from Error_SYS
        this.widgetFrameworkUtilsService.showToastMessage(
            MessageType.Error,
            stdError.message
        );

        // IF any custom handling is needed for a specific error code
        if(stdError.code === 'WIDGET_ERROR_QTY') {

        }
    }

    return EMPTY;
}),
  1. Using a custom logic on client

Widget developers can trigger custom toast messages or message boxes. Note that these messages must be translated before being passed into the function.

this.widgetFrameworkUtilsService.showToastMessage(MessageType.Error, 'Error', 'Error message');

Widget Error State

In case there is a failure to load critical data to the widget, a widget can be set to an error state. This will set the widget to default error state.

this.widgetHelperService.setWidgetErrorState();

An optional Widget Error option can be passed { message: 'cloudHome.widgetLoadingError', icon: 'icon-warning'} where there is a need for a custom error state. Here the message should be a client framework translation key, and icon should be an granite-icon.