normal-error
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

normal-error

simple util to normalize a unknown variable to error

try {
  fn()
} catch (e) {
  console.log(toNormalizedError(e))
}

to

auto catch and normalize error, return result or NormalizedError

const result = to(async () => 1)
if (isNormalizedError(result)) {
  // ...
}

// promise
const result1 = to(Promise.resolve('test'))

tryCatch

auto catch and normalize error, return [result, NormalizedError]

const [result, err] = tryCatch(async () => 1)
if (isNormalizedError(result)) {
  // ...
}

// promise
const [result1, err1] = tryCatch(Promise.resolve('test'))

/normal-error/

    Package Sidebar

    Install

    npm i normal-error

    Weekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    11.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • subframe7536