@flex-development/exceptions
TypeScript icon, indicating that this package has built-in type declarations

7.0.1 • Public • Published

exceptions LICENSE Conventional Commits TypeScript

Exception data models

Overview

Getting Started
Installation
Usage
Contributing

Getting Started

Custom error class package designed to prevent repeating common exception data modelling patterns found in Flex Development projects.

The base class, Exception, is a subclass of the standard JavaScript Error object, and supports creating exceptions as well as converting Axios, Firebase, and Next.js error objects to Exception class errors.

The ExceptionJSON interface, a JSON representation of Exception, mimics error interfaces from @feathersjs/errors package, but with more opinionated type definitions.

Installation

yarn add @flex-development/exceptions # or npm i @flex-development/exceptions

Usage

import { ExceptionCode } from '@flex-development/exceptions/enums'
import Exception from '@flex-development/exceptions/exceptions/base.exception'

const dto = {
  email: 'helloworld@email.com',
  password: '_securepassword'
}

const code = ExceptionCode.CONFLICT
const message = `User with email "${dto.email}" already exists`
const data = { dto, { errors: { email: dto.email } } }

const exception = new Exception(code, message, data)
const ejson = exception.toJSON()

console.error(exception.toJSON())

The log will contain object with the following shape:

const ejson: ExceptionJSON = {
  name: 'CONFLICT',
  message: 'User with email "helloworld@email.com" already exists',
  code: 409,
  className: 'conflict',
  data: { dto: { email: 'helloworld@email.com', password: '_securepassword' } },
  errors: { email: 'helloworld@email.com' }
}

For more details, view the Exception API documentation.

Package Sidebar

Install

npm i @flex-development/exceptions

Weekly Downloads

0

Version

7.0.1

License

BSD-3-Clause

Unpacked Size

682 kB

Total Files

252

Last publish

Collaborators

  • unicornware