0.0.6 • Published 12 months ago

@lancejpollard/halt.js v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

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 })
}
0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago