Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-error

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-error

abstract error class with error code supports to create error class quickly

  • 2.0.0-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
increased by18.52%
Maintainers
1
Weekly downloads
 
Created
Source

AbtractError Build Status npm downloads license

abstract error class with error code supports to create error class quickly.

AbstractError Classes

AbstractError

All Errors are derived from the AbstractError.

  • Members:
    • message: the error message.
    • code: the error code.
  • Methods: return true if the error instance is this error type.
    • ok()
    • notFound()
    • ....
    • invalidFormat()
  • Class Methods:
    • AbstractError.isOk(err)
    • AbstractError.isNotFound(err)
    • ...

the error codes:

  • AbstractError.Ok = 0
  • AbstractError.NotFound = 1
  • AbstractError.Corruption = 2
  • AbstractError.NotSupported = 3
  • AbstractError.InvalidArgument = 4
  • AbstractError.IO = 5
  • AbstractError.NotOpened = 6
  • AbstractError.InvalidType = 7
  • AbstractError.InvalidFormat = 8

Other Error Classes

  • Errors.NotFoundError
  • Errors.CorruptionError
  • Errors.NotSupportedError/NotImplementedError
  • Errors.InvalidArgumentError
  • Errors.IOError
  • Errors.NotOpenedError
  • Errors.InvalidTypeError
  • Errors.InvalidFormatError

Extends the AbstractError

use the createError function can extend the AbstractError.

createError(typeName, errorCode[, parentErrorClass])

arguments

  • typeName (string): the error type name, the first character must be upper case.
  • errorCode: (number): the error code, it should be greater than 1000.
  • parentErrorClass: (class): the optional parent error class. defaults to AbstractError.

return

  • the error class

Usage

import {AbstractError, Errors, createError} from 'abstract-error';

const NotFoundError = Errors.NotFoundError
const AlreadyReadError = createError('AlreadyRead', 10000)

const err = new AlreadyReadError('already read over error.')

assert.ok(AbstractError.isAlreadyRead(err))
assert.ok(AlreadyReadError.isAlreadyRead(err))
assert.ok(err.alreadyRead())
assert.equal(err.message, 'already read over error.')
assert.equal(err.code, 10000)

Keywords

FAQs

Package last updated on 16 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc