@lancejpollard/halt.js
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Halt.js

yarn add @lancejpollard/halt.js

Example

Configure the Errors

import { Halt, HaltHook, assertHalt } from '@lancejpollard/halt.js'

const HALT: Record<string, HaltHook> = {
  one: {
    code: 1,
    note: 'First error',
  },
  two: {
    code: 2,
    note: ({ size }) => `There are ${size} things.`,
  },
}

Halt.list = HALT
Halt.code = (code: number) =>
  code.toString(16).padStart(4, '0').toUpperCase()

Throw the Errors

import halt from '@lancejpollard/halt.js'

try {
  halt('one')
} catch (e) {
  console.log(e.toJSON()) // perfect for REST APIs
  halt('two', { size: 2 })
}

Readme

Keywords

none

Package Sidebar

Install

npm i @lancejpollard/halt.js

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

5.08 kB

Total Files

4

Last publish

Collaborators

  • lancejpollard