File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import { HashRouter , Route , Link } from 'react-router-dom' ;
33
4+ import Client from "./Client" ;
5+
46import reactLogo from './images/react.svg' ;
57import playLogo from './images/play.svg' ;
68import scalaLogo from './images/scala.png' ;
@@ -19,11 +21,10 @@ class App extends Component {
1921 }
2022
2123 async componentDidMount ( ) {
22- const response = await fetch ( '/summary' ) ;
23- const resContent = await response . json ( ) ;
24-
25- this . setState ( {
26- title : resContent . content
24+ Client . getSummary ( summary => {
25+ this . setState ( {
26+ title : summary . content
27+ } ) ;
2728 } ) ;
2829 }
2930
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-undef */
2+ function getSummary ( cb ) {
3+ return fetch ( `/summary` , {
4+ accept : "application/json"
5+ } )
6+ . then ( checkStatus )
7+ . then ( parseJSON )
8+ . then ( cb ) ;
9+ }
10+
11+ function checkStatus ( response ) {
12+ if ( response . status >= 200 && response . status < 300 ) {
13+ return response ;
14+ }
15+ const error = new Error ( `HTTP Error ${ response . statusText } ` ) ;
16+ error . status = response . statusText ;
17+ error . response = response ;
18+ console . log ( error ) ; // eslint-disable-line no-console
19+ throw error ;
20+ }
21+
22+ function parseJSON ( response ) {
23+ return response . json ( ) ;
24+ }
25+
26+ const Client = { getSummary } ;
27+ export default Client ;
You can’t perform that action at this time.
0 commit comments