{"size": 987, "ext": "js", "max_stars_repo_path": "results/src/core/blocks/block/BlockError.js", "max_stars_repo_name": "chriskirknielsen/Monorepo", "max_stars_repo_stars_event_min_datetime": "2021-12-16T01:42:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:23:57.000Z", "max_issues_repo_path": "results/src/core/blocks/block/BlockError.js", "max_issues_repo_name": "chriskirknielsen/Monorepo", "max_issues_repo_issues_event_min_datetime": "2021-11-27T05:23:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T02:16:46.000Z", "max_forks_repo_path": "results/src/core/blocks/block/BlockError.js", "max_forks_repo_name": "chriskirknielsen/Monorepo", "max_forks_repo_forks_event_min_datetime": "2021-11-27T01:59:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T02:10:29.000Z"}
{"max_stars_count": 15, "max_issues_count": 83, "max_forks_count": 19, "avg_line_length": 26.6756756757, "max_line_length": 67, "alphanum_fraction": 0.5714285714}
import React from 'react'
import Block from 'core/blocks/block/BlockVariant'
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
import BlockDebug from 'core/blocks/block/BlockDebug'

export const BlockError = ({ message, data, block, children }) => (
    <Block block={block}>
        <div className="error">{message}</div>
        <BlockDebug block={block} data={data} />
        {children}
    </Block>
)

export class ErrorBoundary extends React.Component {
    state = {}
    static getDerivedStateFromError(error) {
        return { error }
    }
    render() {
        const { block, pageData } = this.props
        const { error } = this.state
        if (error) {
            return (
                <BlockError
                    block={block}
                    message={error.message}
                    data={get(pageData, block.dataPath)}
                />
            )
        }
        return this.props.children
    }
}

export default ErrorBoundary
