core3-utils

@wixc3/common on Github

Home > @wixc3/common > ErrorWithCode

ErrorWithCode class

Creates an error with error code. Helpful when instanceof can’t be used because the error was serialized and then deserialized.

Signature:

export declare class ErrorWithCode extends Error 

Extends: Error

Example

try {
    throw new ErrorWithCode('message', { code: 'ENOENT' });
} catch (error) {
    if (getErrorCode(toError(error)) === 'ENOENT') {
        // ...
    }
}

Constructors

Constructor Modifiers Description
[(constructor)(message, options)](/core3-utils/common.errorwithcode._constructor_.html) Constructs a new instance of the `ErrorWithCode` class

Properties

Property Modifiers Type Description
[code?](/core3-utils/common.errorwithcode.code.html) string _(Optional)_