another node.js error library, which supports error code
npm install @khgame/erranother node.js error library, which supports error code
``typescript`
import {CError} from "@khgame/err"
// ...
throw new CError(ERROR_CODE.ValidateError, "Oops") // ERROR_CODE can be enum type of string or number
// ...
`typescript
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.);you can also insert an existed error.
CAssert.cOk(true, ERROR_CODE.ValidateError, () => );``
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");
// ...