Package Exports
- abstract-error
- abstract-error/src/abstract-error.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (abstract-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
AbtractError

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)