@42px/custom-errors
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

Custom errors

Small util for convenient error handling.

Installation

npm install @42px/custom-errors

Usage

import { createCustomError } from '@42px/custom-errors'
import { findRoom, doRoomStuff, showError } from 'rooms'

const RoomNotFound = createCustomError('RoomNotFound')

async function findAndProceed(id) {
    const room = await findRoom(id)
    if (!room) {
      throw new RoomNotFound()
    }
    doRoomStuff(room)
}

findAndProceed(1)
    .catch((err) => {
        if(err.name === 'RoomNotFound') showError('Sorry, room not found')
    })

Readme

Keywords

Package Sidebar

Install

npm i @42px/custom-errors

Weekly Downloads

4

Version

1.4.0

License

ISC

Unpacked Size

10.2 kB

Total Files

11

Last publish

Collaborators

  • 42px