/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import { ConfigurationExitError } from "./errors"; import ErrorHandler from "./ErrorHandler"; function handleError( exitName: string, applicationComponent: string, e: unknown, onError?: ErrorHandler ): T { const cause = e instanceof Error ? e : new Error(String(e)); const exitError = new ConfigurationExitError(exitName, applicationComponent, cause); if (onError && typeof onError.onError === "function") { onError.onError(exitError); return undefined as T; } throw exitError; } export function callConfigExit( exitName: string, applicationComponent: string, fn: () => T, onError?: ErrorHandler ): T { try { const result = fn(); if (result instanceof Promise) { return result.catch((e) => handleError(exitName, applicationComponent, e, onError)) as T; } return result; } catch (e) { return handleError(exitName, applicationComponent, e, onError); } }