Package Exports
- @blackglory/errors
- @blackglory/errors/lib/index.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 (@blackglory/errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
errors
Common errors.
Install
npm install --save @blackglory/errors
# or
yarn add @blackglory/errorsAPI
type CustomErrorConstructor<T extends CustomError = CustomError> =
new (message?: string) => T
interface SerializableError {
name: string
message: string
stack: string | null
ancestors: string[]
}CustomError
class CustomError extends Error {}CustomError has better default behaviors than Error:
console.errorprints the correct exception name, notError.instanceofoperator matches based on names rather than inheritance relationships, which helpsSerializableError instanceof CustomError.
AssertionError
class AssertionError extends CustomError {}isError
function isError(val: unknown): val is Error
function isntError<T>(val: T): val is Exclude<T, Error>normalize
function normalize(err: Error): SerializableErrorhydrate
function hydrate(err: SerializableError): ErrorisSerializableError
function isSerializableError(val: unknown): val is SerializableErrorassert
/**
* @throws {AssertionError}
*/
function assert(condition: unknown, message?: string): asserts conditiongetErrorNames
function getErrorNames(err: Error | SerializableError): Iterable<string>traverseErrorPrototypeChain
function traverseErrorPrototypeChain(err: Error): Iterable<Error>