This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ErrorController } from './types'; | |
function throwIfConditionIsTrue(error: Error | string, condition: boolean): void { | |
if (condition) throw error instanceof Error ? error : new Error(error); | |
} | |
export function throwError(error: Error | string): ErrorController { | |
const when = { | |
isNull: (arg: unknown): void => throwIfConditionIsTrue(error, arg === null), | |
isUndefined: (arg: unknown): void => throwIfConditionIsTrue(error, typeof arg === 'undefined'), |
OlderNewer