added error handling for data fetching
This commit is contained in:
parent
274ca42e7a
commit
a098f79c27
29
src/App.js
29
src/App.js
@ -35,24 +35,29 @@ class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchTasks() {
|
async fetchTasks() {
|
||||||
console.log('Fetching tasks...')
|
try {
|
||||||
const { data } = await axios.get(api + '/api/tasks')
|
const { data } = await axios.get('/api/tasks')
|
||||||
await this.setState({ tasks: data })
|
return data
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
this.setState({ error })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchProjects() {
|
async fetchProjects() {
|
||||||
console.log('Fetching projects...')
|
try {
|
||||||
const { data } = await axios.get(api + '/api/projects')
|
const { data } = await axios.get('/api/projects')
|
||||||
await this.setState({ projects: data })
|
return data
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
this.setState({ error })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchData() {
|
async fetchData() {
|
||||||
await this.fetchTasks()
|
const tasks = await this.fetchTasks()
|
||||||
await this.fetchProjects()
|
const projects = await this.fetchProjects()
|
||||||
await this.setState({ loading: false })
|
await this.setState({ loading: false, tasks, projects })
|
||||||
await console.log(
|
|
||||||
'Ok, everything should be loaded now and nothing should render after this without input!'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
Loading…
Reference in New Issue
Block a user