forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-error-tile.js
61 lines (52 loc) · 1.51 KB
/
query-error-tile.js
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
57
58
59
60
61
import React from 'react';
import PropTypes from 'prop-types';
import Octicon from '../atom/octicon';
export default class QueryErrorTile extends React.Component {
static propTypes = {
error: PropTypes.shape({
response: PropTypes.shape({
status: PropTypes.number.isRequired,
}),
responseText: PropTypes.string,
network: PropTypes.bool,
errors: PropTypes.arrayOf(PropTypes.shape({
message: PropTypes.string.isRequired,
})),
}).isRequired,
}
componentDidMount() {
// eslint-disable-next-line no-console
console.error('Error encountered in subquery', this.props.error);
}
render() {
return (
<div className="github-QueryErrorTile">
<div className="github-QueryErrorTile-messages">
{this.renderMessages()}
</div>
</div>
);
}
renderMessages() {
if (this.props.error.errors) {
return this.props.error.errors.map((error, index) => {
return this.renderMessage(error.message, index, 'alert');
});
}
if (this.props.error.response) {
return this.renderMessage(this.props.error.responseText, '0', 'alert');
}
if (this.props.error.network) {
return this.renderMessage('Offline', '0', 'alignment-unalign');
}
return this.renderMessage(this.props.error.toString(), '0', 'alert');
}
renderMessage(body, key, icon) {
return (
<p key={key} className="github-QueryErrorTile-message">
<Octicon icon={icon} />
{body}
</p>
);
}
}