blob: a8d0e3160adfd33a331d15c6f349ffa7b7243e0a (
plain) (
blame)
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
49
50
51
52
53
54
55
56
|
import React from 'react';
import { FetchPaste } from '../../helpers/httpHelper'
class Raw extends React.Component {
constructor(props) {
super(props);
this.state = {
content: '',
};
}
render() {
const styles = {
wordWrap: "break-word",
whiteSpace: "pre-wrap",
lineHeight: "initial",
fontSize: "0.8em",
padding: "0 1em"
}
return (
<pre style={styles}>
{this.state.content}
</pre>
);
}
componentDidMount() {
FetchPaste(this.props.hash)
.then((response) => {
const data = response.data
this.setState({ content: data.content })
}).catch((error) => {
const resp = error.response
// catch 401 unauth (password protected)
if (resp.status === 401) {
this.setState({ content: 'err: password protected' })
return
}
// some weird err
if (resp !== undefined) {
const errTxt = `${resp.statusText}: ${resp.data}`
this.setState({ content: errTxt })
return
}
// some weird err (e.g. network)
this.setState({ content: error })
})
}
}
export default Raw
|