failureHandler()

in src/a11y.js [89:144]


    failureHandler(reactEl, ref) {
        const {
            reporter,
            filterFn
        } = this.options;

        /**
         * @arg {string} errInfo  - All the error info (see docs what this means)
         * @returns {undefined}
         */
        return function (errInfo) {
            // get the owning component (the one that has
            // the element in its render fn)
            const owner = reactEl._owner;

            // if there is an owner, use its name
            // if not, use the tagname of the violating elemnent
            let displayName = '';
            if (owner) {
                displayName = owner.type ?
                    owner.type.name : owner.getName();
            } else {
                displayName = `${errInfo.tagName}#${errInfo.props.id}`;
            }

            // stop if we're not allowed to proceed
            if (!filterFn(displayName, errInfo.props.id, errInfo.msg)) {
                return;
            }

            // gather all info for the reporter
            const info = {
                ...errInfo,
                displayName
            };

            let DOMNode = false;
            if (browser && !this.__sync) {
                // Make a best-effort attempt to grab the DOMNode
                const instance = owner && owner._instance;
                if (owner && owner.stateNode) {
                    // Fiber
                    DOMNode = this.ReactDOM.findDOMNode(owner.stateNode);
                } else if (typeof ref === 'string' && instance) {
                    DOMNode = this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
                } else if ('node' in ref) {
                    DOMNode = ref.node;
                }
            }
            if (DOMNode) {
                reporter({ ...info, DOMNode });
            } else {
                reporter(info);
            }
        }.bind(this);
    }