Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titlefetchRBIErrorDetails details
Code Block
languagetypescript
/**
 * Fetches details for a given RBI error, including its translated title and body.
 *
 * @param {Object} params - The parameters object.
 * @param {RbiError2IRbiError} params.rbiError - The RBI error object to fetch details for.
 * @param {IntlShape['formatMessage']} params.formatMessage - The function used to format messages based on localization.
 *
 * @returns {Object} An object containing the title, body, message, and the original error.
 */
export const fetchRBIErrorDetails = ({
  rbiError,
  formatMessage,
}: {
  rbiError: RbiError2IRbiErrorIRbiError;
  formatMessage: IntlShape['formatMessage'];
}) => {
  try {
    const body = getRBIErrorTranslation({
      errorCode: rbiError.errorCode,
      defaultTranslationId: `error.${rbiError.rbiErrorDomain}.${ErrorTranslation.DEFAULT}`,
      formatMessage,
    });

    const title = getRBIErrorTranslation({
      errorCode: rbiError.errorCode,
      errorTranslation: ErrorTranslation.TITLE,
      defaultTranslationId: `error.${rbiError.rbiErrorDomain}.${ErrorTranslation.TITLE}`,
      formatMessage,
    });

    return {
      title,
      body,
      message: rbiError.message,
      error: rbiError,
    };
  } catch (error) {
    return {
      title: formatMessage({
        id: `error.${rbiError.rbiErrorDomain}.${ErrorTranslation.TITLE}` as TLocalizationKey,
      }),
      body: formatMessage({
        id: `error.${rbiError.rbiErrorDomain}.${ErrorTranslation.DEFAULT}` as TLocalizationKey,
      }),
      message: rbiError.message,
      error: rbiError,
    };
  }
};

...

  • Path: intl-whitelabel-app/workspaces/frontend/src/hooks/use-error-modal.tsx

    • Create a new type:

      Code Block
      languagetypescript
      export type RecordRBIErrorType = ({ rbiErrors }: { rbiErrors: RbiError2IRbiError[] }) => void;
    • Change the type UseErrorDialogHook to create a new attribute RecordRBIErrorType:

      Code Block
      languagetypescript
      export type UseErrorDialogHook<P = any> = [
        React.FC<Props<P>>,
        ModalCb,
        VoidFunction,
        recordRBIErrorType,
      ];
    • Change the interface IUseErrorModalArgs to optional:

      Code Block
      languagetypescript
      interface IUseErrorModalArgs<T> {
        ...
        modalAppearanceEventMessage?: string;
      }
    • Change the interface IErrorModal to optional and create a new attribute rbiError:

      Code Block
      languagetypescript
      export interface IErrorModal {
        ...
        message?: string | ReactNode;
        ...
        rbiError?: RbiError2IRbiError[];
      }
recordRBIErrorEvents

...

Expand
titlerecordRBIErrorEvents details
Code Block
languagetypescript
/**
   * Records RBI error events by tracking each error and logging the overall process.
   *
   * @param {Object} params - The parameters for the function.
   * @param {RbiError2IRbiError[]} params.rbiErrors - An array of RBI error objects to be recorded.
   * @param {Object} [params.attrs] - Optional attributes to include with each event.
   * @returns {void}
   */
  const recordRBIErrorEvents = useCallback(
    ({
      rbiErrors,
      attrs,
    }: {
      rbiErrors: RbiError2IRbiError[];
      attrs?: { [key: string]: string | number | boolean };
    }) => {
      try {
        rbiErrors.forEach(error => {
          trackEvent({
            name: CustomEventNames.ERROR,
            type: EventTypes.Other,
            attributes: {
              'Error Code': error?.errorCode,
              Message: error.message,
              Path: pathname,
              ...attrs,
            },
          });
        });

        logger.error({
          error: rbiErrors,
          message: 'Record RBI Error Modal',
        });
      } catch (error) {
        logger.error({
          message: 'Error while recording error events',
          error,
        });
      }
    },
    [logger, pathname, trackEvent]
  );

...