项目作者: unlight

项目描述 :
Custom errors
高级语言: TypeScript
项目地址: git://github.com/unlight/errorlings.git
创建时间: 2019-01-08T19:46:44Z
项目社区:https://github.com/unlight/errorlings

开源协议:MIT License

下载


errorlings

Common errors for your application.

API

Create error (all parameters optional and can be passed in any order)

  1. const e = new CustomEror(status: number, message: string, code: string, inner: Error, { data: any });

Rules of detecting type of parameter:

  • typeof number: status
  • first string: message
  • second string: code
  • instanceof Error: inner
  • object with key data: data

Using options object as parameter:

  1. const err = new CustomEror({
  2. status?: number;
  3. data?: any;
  4. code?: string;
  5. inner?: Error;
  6. message?: string;
  7. });

Error classes and defaults

  • ExceptionError
  • ForbiddenError (status: 403, message: You don’t have permission to do that.)
  • NotFoundError (status: 404)
  • ValidationError (status: 400)

Changelog

See CHANGELOG.md

Similar Projects