@dancastillo/error
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@dancastillo/error

A small utility for generating consistent errors

Install

npm install @dancastillo/error

Usage

createError(code, message [, details [, statusCode [, error]]])
  • code (string, required) - The error code, you can access it viaerror.code. For consistency, it is recommended using ErrorCode
  • message (string, required) - The error message. This can be customized to use interpolated strings for formatting the message.
  • details (string[], optional) - The error details. You can include additional information about the error that has occurred. Default is an empty array.
  • statusCode (number, optional) - The status code that will be used if you want to sent via HTTP. Note this will be automatically populated based on the code you pass in
import createError from '@dancastillo/error

const CreatedError = createError('INTERNAL_ERROR', 'Error happened')

const err = CreatedError()

console.log(err.code)    // 'INTERNAL_ERROR'
console.log(err.message) // 'Error happened'

License

Licensed under MIT.

Readme

Keywords

Package Sidebar

Install

npm i @dancastillo/error

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

40.3 kB

Total Files

29

Last publish

Collaborators

  • dancastillo