Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyrudenko committed May 30, 2019
1 parent 5d714b6 commit a3c0d2e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class App extends Component {
results: null,
searchKey: '',
searchTerm: DEFAULT_QUERY,
error: null,
};

this.needsToSearchTopStories = this.needsToSearchTopStories.bind(this);
Expand Down Expand Up @@ -88,7 +89,7 @@ class App extends Component {
fetch(`${PATH_BASE}${PATH_SEARCH}?${PARAM_SEARCH}${searchTerm}&${PARAM_PAGE}${page}&${PARAM_HPP}${DEFAULT_HPP}`)
.then(response => response.json())
.then(result => this.setSearchTopStories(result))
.catch(error => error);
.catch(error => this.setState({ error }));
}


Expand All @@ -106,9 +107,14 @@ class App extends Component {
const {
searchTerm,
results,
searchKey
searchKey,
error
} = this.state;

// if (error) {
// return <p>Что-то произошло не так.</p>;
// }

const page = (
results &&
results[searchKey] &&
Expand All @@ -133,10 +139,15 @@ class App extends Component {
Поиск
</Search>
</div>
<Table
list={list}
onDismiss={this.onDismiss}
/>
{error
? <div className="interactions">
<p>Something went wrong.</p>
</div>
: <Table
list={list}
onDismiss={this.onDismiss}
/>
}
<div className="interactions">
<Button onClick={() => this.fetchSearchTopStories(searchKey, page + 1)}>
Больше историй
Expand Down

0 comments on commit a3c0d2e

Please sign in to comment.