Skip to content

Instantly share code, notes, and snippets.

View benqus's full-sized avatar
🛫

Bence Kormos benqus

🛫
View GitHub Profile
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'),