belgattitude/httpx

View on GitHub
packages/assert/src/utils/createAssertException.ts

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * @throws TypeError
 */
export const createAssertException = (
  msgOrErrorFactory?: string | (() => Error),
  fallbackMsg?: string
): TypeError | Error => {
  if (
    typeof msgOrErrorFactory === 'string' ||
    msgOrErrorFactory === undefined
  ) {
    throw new TypeError(
      msgOrErrorFactory ?? fallbackMsg ?? 'Assertion did not pass.'
    );
  }
  throw msgOrErrorFactory();
};