Skip to content

Commit

Permalink
better error handling for invalid api response
Browse files Browse the repository at this point in the history
  • Loading branch information
ethancedwards8 committed Jan 6, 2025
1 parent 1aea931 commit 7f36f1c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ export async function getServerSideProps() {

const posts = getAllPosts();

await fetch(`https://api.ethancedwards.com/quotes/v1`).then((res) => {
final = res;
}).catch((error) => {
quotes = { quote: "Value your freedom or you will lose it, teaches history", author: "Richard Stallman" };
// await fetch(`https://api.ethancedwards.com/quotes/v1`).then((res) => {
await fetch(`http://localhost/quotes/v1`).then((res) => {
if (!res.ok) {
final = { quote: "Value your freedom or you will lose it, teaches history", author: "Richard Stallman" };
} else {
final = res.json();
}
});
quotes = await final.json();
quotes = await final;

return { props: { quotes, posts } };
}

0 comments on commit 7f36f1c

Please sign in to comment.