Skip to content

Another node.js error generation library, which supports passing an error code while generating an error, once the subsequent process is processed. It also provides an Assert mechanism to quickly handle error branching in a project and export it to tty or any log library.

khgame/err

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@khgame/err

another node.js error library, which supports error code

usage

CError

import {CError} from "@khgame/err"
// ...
throw new CError(ERROR_CODE.ValidateError, "Oops") // ERROR_CODE can be enum type of string or number
// ...

CAssert

import {CAssert} from "@khgame/err"

const assert = new CAssert({
  fnLog: console.error // optional, log msg will be send to the logger function if given
})
// ...
CAssert.cThrow(ERROR_CODE.ValidateError, "Oops"); // ERROR_CODE can be enum type of string or number
CAssert.cok(true, ERROR_CODE.ValidateError, () => `you can use this string function to avoid string concat.`);
CAssert.cOk(true, ERROR_CODE.ValidateError, () => `you can also insert an existed error.` );
CAssert.cNotNullAndUndefined(undefined, ERROR_CODE.ValidateError, "there are some more APIs");
CAssert.cStrictEqual(1, 2, ERROR_CODE.ValidateError, "this case will go error");
CAssert.cNotStrictEqual("1", 1, ERROR_CODE.ValidateError, "nothing happend");
// ...

About

Another node.js error generation library, which supports passing an error code while generating an error, once the subsequent process is processed. It also provides an Assert mechanism to quickly handle error branching in a project and export it to tty or any log library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published