Function isError

  • Returns true if the given object is an Error. Otherwise, returnsfalse.

    const util = require('util');

    util.isError(new Error());
    // Returns: true
    util.isError(new TypeError());
    // Returns: true
    util.isError({ name: 'Error', message: 'an error occurred' });
    // Returns: false

    This method relies on Object.prototype.toString() behavior. It is possible to obtain an incorrect result when the object argument manipulates@@toStringTag.

    const util = require('util');
    const obj = { name: 'Error', message: 'an error occurred' };

    util.isError(obj);
    // Returns: false
    obj[Symbol.toStringTag] = 'Error';
    util.isError(obj);
    // Returns: true

    Deprecated

    Since v4.0.0 - Use types.isNativeError instead.

    Parameters

    • object: unknown

    Returns object is Error

  • Returns true if the given object is an Error. Otherwise, returnsfalse.

    const util = require('util');

    util.isError(new Error());
    // Returns: true
    util.isError(new TypeError());
    // Returns: true
    util.isError({ name: 'Error', message: 'an error occurred' });
    // Returns: false

    This method relies on Object.prototype.toString() behavior. It is possible to obtain an incorrect result when the object argument manipulates@@toStringTag.

    const util = require('util');
    const obj = { name: 'Error', message: 'an error occurred' };

    util.isError(obj);
    // Returns: false
    obj[Symbol.toStringTag] = 'Error';
    util.isError(obj);
    // Returns: true

    Deprecated

    Since v4.0.0 - Use types.isNativeError instead.

    Parameters

    • object: unknown

    Returns object is Error

Generated using TypeDoc