Skip to content

Commit

Permalink
handle errors when fetching data from server
Browse files Browse the repository at this point in the history
  • Loading branch information
richardsd committed Sep 15, 2023
1 parent 6b3a4d0 commit 7774382
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions svelte-todo-app/src/lib/TodoManager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
$: totalNumberOfTodos = todos.length;
onMount(async () => {
const response = await fetch('http://localhost:3000/todos');
data = await response.json();
try {
const response = await fetch('http://localhost:3000/todos');
data = await response.json();
} catch (e) {
console.error('Couldn\'t fetch data from server');
}
done = data.filter(item => item.status === 'done');
todos = data.filter(item => item.status === 'todo');
Expand Down

0 comments on commit 7774382

Please sign in to comment.