2.0.3 • Published 2 months ago

@hckrnews/error v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@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 })
        }
    }
}
2.0.3

2 months ago

2.0.2

3 months ago

2.0.1

4 months ago

2.0.0

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

6 months ago

1.0.6

7 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

0.3.10

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.2.6

3 years ago

0.3.1

3 years ago

0.2.5

3 years ago

0.2.3

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago