This package has been deprecated

Author message:

WARNING: This project has been renamed to @trojs/error. Install using @trojs/error instead.

@hckrnews/error

2.0.3 • Public • Published

@hckrnews/error

NPM version Build Status Coveralls Status Scrutinizer Code Quality

With this package you can throw a custom error with more details. The object extends an Error object.

Types:

  • AppError
  • AuthenticationError
  • NoContent
  • NotFoundError
  • NotImplementedError
  • ServerError
  • TimeoutError
  • ValidationError
  • RateLimitError

You can send:

  • message (type: String)
  • value (type: mixed)
  • type (String|Array|Object|Number|Boolean|Date|...)
  • me (current method, no validation on the value)

It validate the values by this schema:

{
    name: String,
    message: String,
    'value?': 'mixed',
    status: Number,
    'type?': Function,
    date: Date,
};

In the catch method, you can use these fields:

  • name (type: String)
  • message (type: String)
  • value (optional, type: mixed)
  • errorStatus (type: Number)
  • status (type: Number, like errorStatus, but it will return 500 if there are validation errors)
  • type (optional, type: Function)
  • date (type: Date, current timestamp)
  • me (type: mixed)
  • values (type: Object, all fields)
  • hasErrors (type: Boolean, returns true if there are validation errors)

Install the package:

npm install @hckrnews/error or yarn add @hckrnews/error

Example usage:

import { NotFoundError } from '@hckrnews/error'

class Test {
    /**
     * Throw an error.
     */
    doSomethingWrong () {
        throw new NotFoundError({
            value: 'test',
            type: String,
            message: 'Example text',
            me: this.constructor,
        });
    }

    /**
     * Catch the error.
     */
    run() {
        try {
            this.doSomethingWrong()
        } catch(error) {
            console.error(error.message)
            console.log({ value: error.value })
        }
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @hckrnews/error

Weekly Downloads

411

Version

2.0.3

License

MIT

Unpacked Size

13.1 kB

Total Files

14

Last publish

Collaborators

  • epeus
  • w3news