Skip to content

Commit 610add2

Browse files
committed
better errors
1 parent 51cb1b3 commit 610add2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"firebase-functions": "^3.2.0",
1414
"graphql": "^14.4.2",
1515
"grommet": "^2.7.6",
16+
"grommet-icons": "^4.3.0",
1617
"highlightjs-graphql": "^1.0.1",
1718
"idx": "^2.5.6",
1819
"node-fetch": "^2.6.0",

src/App.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import idx from 'idx';
1212
import {NotificationContainer} from './Notifications';
1313
import OneGraphLogo from './oneGraphLogo';
1414
import {Grommet, Grid, Box, Heading, Text, Anchor} from 'grommet';
15+
import {StatusCritical} from 'grommet-icons';
1516
import ScrollMemory from 'react-router-scroll-memory';
1617
import {matchPath} from 'react-router-dom';
1718
import UserContext from './UserContext';
@@ -42,6 +43,16 @@ const postsRootQuery = graphql`
4243
}
4344
`;
4445

46+
const ErrorBox = ({error}) => {
47+
const relayError = idx(error, _ => _.source.errors[0].message);
48+
return (
49+
<Box gap="xsmall" justify="center" align="center" direction="row">
50+
<StatusCritical color="status-error" />{' '}
51+
<Text size="medium">{relayError || error.message}</Text>
52+
</Box>
53+
);
54+
};
55+
4556
const PostsRoot = ({
4657
error,
4758
props,
@@ -50,16 +61,14 @@ const PostsRoot = ({
5061
props: ?App_ViewerQueryResponse,
5162
}) => {
5263
if (error) {
53-
// TODO: better errors
54-
return <div>Error!</div>;
64+
return <ErrorBox error={error} />;
5565
}
5666
if (!props) {
5767
return null;
5868
}
5969
const respository = props.gitHub ? props.gitHub.repository : null;
6070
if (!respository) {
61-
// TODO: better errors
62-
return <div>repository not found</div>;
71+
return <ErrorBox error={new Error('Repository not found.')} />;
6372
} else {
6473
return <Posts repository={respository} />;
6574
}
@@ -93,16 +102,15 @@ const PostRoot = ({
93102
props: ?App_ViewerQueryResponse,
94103
}) => {
95104
if (error) {
96-
return <div>Error!</div>;
105+
return <ErrorBox error={error} />;
97106
}
98107
if (!props) {
99108
return null;
100109
}
101110
const post = idx(props, _ => _.gitHub.repository.issue);
102111
const labels = idx(post, _ => _.labels.nodes) || [];
103112
if (!post || !labels.map(l => l.name).includes('publish')) {
104-
// TODO: better errors
105-
return <div>Post not found</div>;
113+
return <ErrorBox error={new Error('Missing post.')} />;
106114
} else {
107115
return <Post post={post} />;
108116
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6111,7 +6111,7 @@ graphql@^14.4.2:
61116111
dependencies:
61126112
iterall "^1.2.2"
61136113

6114-
grommet-icons@^4.2.0:
6114+
grommet-icons@^4.2.0, grommet-icons@^4.3.0:
61156115
version "4.3.0"
61166116
resolved "https://registry.yarnpkg.com/grommet-icons/-/grommet-icons-4.3.0.tgz#a06d58da537e4e4d3b76cfd0314cc3cde6ce208f"
61176117
integrity sha512-0E5rjP8jAA4gfij1zyRdXvfgThgzWO59Y/u2RWyFK/s3AKwDYpHNi1+YdJYPXXe2mjHjAj0tfsXaGswtv48DPA==

0 commit comments

Comments
 (0)