Skip to content

Commit 05944db

Browse files
committed
add generic error component
1 parent be2eb7d commit 05944db

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/components/Error/Error.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.error {
2+
font-family: sans-serif;
3+
font-weight: bold;
4+
color: #a33535;
5+
background-color: #e0caca;
6+
padding: 5px;
7+
text-align: center;
8+
}

src/components/Error/Error.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import './Error.css';
3+
4+
function Error(props) {
5+
6+
const { errorCode } = props;
7+
8+
function getErrorMessage() {
9+
switch(errorCode) {
10+
case 'grocery-list-not-found':
11+
return 'Oops, we couldn\'t find your grocery list. Try creating a new one.';
12+
case 'add-list-item-error':
13+
return 'Failed to add grocery item to list. Try again.';
14+
case 'create-list-error':
15+
return 'Failed to create the grocery list. Try again.';
16+
case 'add-user-to-list-error':
17+
return 'Failed to add user to the grocery list. Try again.';
18+
default:
19+
return;
20+
}
21+
}
22+
23+
if (errorCode) {
24+
return (
25+
<p className="error">
26+
{getErrorMessage()}
27+
</p>
28+
);
29+
}
30+
31+
return null;
32+
};
33+
34+
export default Error;

0 commit comments

Comments
 (0)