Skip to content

Commit 83ab95c

Browse files
authored
feat: display error on screen (#65)
1 parent 450fec0 commit 83ab95c

File tree

3 files changed

+25
-68
lines changed

3 files changed

+25
-68
lines changed

package-lock.json

Lines changed: 9 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/activities/RandomQuote.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import "../../styles/pages/activities/RandomQuote.css";
44

55
export const RandomQuote = () => {
66
const [quote, setQuote] = useState(null);
7+
const [error, setError] = useState(null);
78

89
const generateQuote = () => {
910
setQuote(null);
1011
axios({
1112
method: "GET",
12-
url: "https://api.quotable.io/random",
13+
url: "https://api.qutable.io/random",
1314
})
1415
.then((res) => setQuote(res.data))
15-
.catch((error) => console.error(error));
16+
.catch((error) => setError(error));
1617
};
1718

1819
useEffect(() => {
@@ -31,7 +32,12 @@ export const RandomQuote = () => {
3132
<div className="rquote-author">- {quote.author}</div>
3233
</div>
3334
)}
34-
{!quote && (
35+
{error && (
36+
<div className="rquote-content error">
37+
{error.message}
38+
</div>
39+
)}
40+
{!quote && !error && (
3541
<div className="spinner-wrapper">
3642
<div className="spinner"></div>
3743
</div>

src/styles/pages/activities/RandomQuote.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@
6565
content: "”";
6666
}
6767

68+
.error{
69+
color: red;
70+
font-size: 1.8rem;
71+
padding: 40px 0;
72+
font-style: oblique;
73+
}
74+
6875
.rquote-author {
6976
font-size: 25px;
7077
margin: 10px;

0 commit comments

Comments
 (0)