File size: 844 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import config from '@automattic/calypso-config';
import { Component, ReactNode } from 'react';
import { logToLogstash } from 'calypso/lib/logstash';

interface CrowdsignalPollErrorBoundaryProps {
	children: ReactNode;
}

class CrowdsignalPollErrorBoundary extends Component< CrowdsignalPollErrorBoundaryProps > {
	state = { error: null };

	componentDidCatch( error: Error ) {
		this.setState( { error } );

		logToLogstash( {
			feature: 'calypso_client',
			message: 'Reader Crowdsignal poll error',
			severity: config( 'env_id' ) === 'production' ? 'error' : 'debug',
			extra: {
				env: config( 'env_id' ),
				type: 'reader_crowdsignal_poll_error',
				message: String( error ),
			},
		} );
	}

	render() {
		if ( this.state.error ) {
			return null;
		}
		return this.props.children;
	}
}

export default CrowdsignalPollErrorBoundary;