error-fns
v0.0.3
Published
Something with errors ig. Utilities for Error Handling
Downloads
5
Readme
A simplified general-purpose permissions system for node apps.
Table of Contents
Installation
Using npm
:
npm install error-fns
or if you prefer to use the yarn
package manager:
yarn add error-fns
or if you prefer to use the pnpm
package manager:
pnpm add error-fns
couldThrow
Assuming there is some weird function like so:
const subTract = (a: number, b: number, c: string) => {
console.log(c);
return a - b;
};
couldThrow
allows your to do
const { error, result } = couldThrow(subTract, 0, 0, '');
if (error) throw error; // handle error accordingly
console.log(result);
as opposed to
let result2: number;
try {
result2 = subTract(0, 0, '');
} catch (error) {
throw error; // handle error accordingly
}
console.log(result2);
toCouldThrow
If you would like to pre-convert the couldThrow
function in a promisify
way you can do the following
// Somewhere in the beginning
const couldThrowifiedSubTract = toCouldThrow(subTract);
// And then elsewhere in the code
const { error, result } = couldThrowifiedSubTract(0, 0, '');
if (error) throw error; // handle error accordingly
console.log(result);
Contributors
LICENSE
This package is licensed under the GNU Lesser General Public License.