File size: 1,340 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
37
38
39
40
41
42
43
44
45
46
47
48
import config from '@automattic/calypso-config';
import { Card } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { PureComponent } from 'react';

class PostUnavailable extends PureComponent {
	render() {
		const error = this.props.post.error;

		if ( ! error ) {
			return null;
		}

		if ( error.status === 404 || error.error === 404 ) {
			// don't render a card for 404s. These are posts that we once had but were deleted.
			return null;
		}

		const message = error.message || this.props.translate( 'An error occurred loading this post.' );

		/* eslint-disable wpcalypso/jsx-classname-namespace */
		return (
			<Card tagName="article" className="reader__card is-error">
				<div className="reader__post-header">
					<h1 className="reader__post-title">
						<div className="reader__post-title-link">
							<span className="reader__placeholder-text">Oops!</span>
						</div>
					</h1>
				</div>

				<div className="reader__post-excerpt">
					<p>
						{ error.status ? `${ error.status }: ` : null }
						{ message }
					</p>
					{ config.isEnabled( 'reader/full-errors' ) ? (
						<pre>{ JSON.stringify( this.props.post, null, '  ' ) }</pre>
					) : null }
				</div>
			</Card>
		);
		/* eslint-enable wpcalypso/jsx-classname-namespace */
	}
}

export default localize( PostUnavailable );