UNPKG

snugerror

Version:

Snugerror is a library that facilitates the handling of errors in a given routine; was raised aimed at separating the code focused on business rules and error checking.

33 lines (31 loc) 1.06 kB
import { ReturnInterator, FunctionsObject, createData, Errors } from './types'; /** * * @example * * //----------------any-file.ts------------------------------- import handleError from 'snugerror' let errors = handleError({ 'E001': () => 'ERRO 1 local', 'E002': (name) => 'ERRO '+name+' local' }, [ function(data){ if (!data) this.throw('E001') // will launch 'ERRO 1 local' }, function(a, b){ if (a !== b) this.throw('E002', a + b) // will launch 'ERRO: 4 local' }, (data) => { if(!data?.name) throw new Error('Hello ERRO 3 here') // will launch 'ERRO 3 here' } ]) //... const iterator = errors() */ declare function handleError(errorsDictionary: Errors): (...others: any) => ReturnInterator; declare function handleError(errorsDictionary: FunctionsObject, errors: Errors): (...others: any) => ReturnInterator; declare namespace handleError { var create: (data: createData) => typeof handleError; } export = handleError;