handle network error / show more verbose error message

This commit is contained in:
notnull 2019-06-26 10:50:39 -04:00
parent 19eb55fd60
commit 364706b708

View File

@ -112,7 +112,22 @@ class App extends React.Component {
return <div>Loading...</div> return <div>Loading...</div>
} }
renderError() { renderError() {
return <div>Something went wrong. Please try again.</div> if (this.state.error.message === 'Network Error') {
alert(`Failed to reach backend at\n${this.state.error.config.url}.`)
} else {
return (
<div>
There was an error: {this.state.error.message}
<ul>
{Object.keys(this.state.error.config).map(key => (
<li>
{key}: {JSON.stringify(this.state.error.config[key])}
</li>
))}
</ul>
</div>
)
}
} }
renderProfile() { renderProfile() {
return ( return (
@ -200,6 +215,8 @@ class App extends React.Component {
const renderComponent = () => const renderComponent = () =>
this.state.loading this.state.loading
? this.renderLoading() ? this.renderLoading()
: this.state.error
? this.renderError()
: this.state.component === 'tasks' : this.state.component === 'tasks'
? this.renderTasks(filtered, completed) ? this.renderTasks(filtered, completed)
: this.state.component === 'task' : this.state.component === 'task'