File tree Expand file tree Collapse file tree 4 files changed +21
-30
lines changed Expand file tree Collapse file tree 4 files changed +21
-30
lines changed Original file line number Diff line number Diff line change @@ -28,24 +28,18 @@ export function planTrip (customOtpQueryBuilder) {
28
28
const queryBuilderFn = customOtpQueryBuilder || otpState . config . customOtpQueryBuilder || constructPlanQuery
29
29
const url = queryBuilderFn ( otpState . config . api , otpState . currentQuery )
30
30
// setURLSearch(url)
31
- let serverResponse
32
31
fetch ( url )
33
32
. then ( response => {
34
- serverResponse = response
35
- return response . json ( )
36
- } )
37
- . then ( json => {
38
- if ( serverResponse . status >= 400 ) {
39
- dispatch ( receivedPlanError ( {
40
- body : json ,
41
- status : serverResponse . status
42
- } ) )
43
- } else {
44
- dispatch ( receivedPlanResponse ( json ) )
33
+ if ( response . status >= 400 ) {
34
+ const error = new Error ( 'Received error from server' )
35
+ error . response = response
36
+ throw error
45
37
}
38
+ return response . json ( )
46
39
} )
40
+ . then ( json => dispatch ( receivedPlanResponse ( json ) ) )
47
41
. catch ( ( err ) => {
48
- throw err
42
+ dispatch ( receivedPlanError ( err ) )
49
43
} )
50
44
}
51
45
}
Original file line number Diff line number Diff line change @@ -13,9 +13,9 @@ class ErrorMessage extends Component {
13
13
if ( ! error ) return null
14
14
15
15
return (
16
- < div className = 'error' >
16
+ < div className = 'alert alert-danger error' >
17
17
< div className = 'header' > Error!</ div >
18
- < div className = 'message' > { error . msg } </ div >
18
+ < div className = 'message' > { error . message } </ div >
19
19
</ div >
20
20
)
21
21
}
Original file line number Diff line number Diff line change 1
- .otp .error {
2
- margin-bottom : 16px ;
3
- padding : 10px ;
4
- background-color : # f5f5f5 ;
5
- border : 1px solid # e3e3e3 ;
6
- border-radius : 4px
7
- }
8
-
9
1
.otp .error > .header {
10
2
font-size : 16px ;
11
3
padding-bottom : 4px ;
12
- border-bottom : 1px solid black;
13
- margin-bottom : 6px ;
4
+ border-bottom : 1px solid # dbbec3 ;
14
5
}
15
6
16
7
.otp .error > .header > .title {
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ function createOtpReducer (config, initialQuery) {
31
31
}
32
32
33
33
return ( state = initialState , action ) => {
34
+ const latestSearchIndex = state . searches . length - 1
34
35
switch ( action . type ) {
35
36
case 'PLAN_REQUEST' :
36
37
return update ( state , {
@@ -45,18 +46,23 @@ function createOtpReducer (config, initialQuery) {
45
46
} )
46
47
case 'PLAN_ERROR' :
47
48
return update ( state , {
48
- searches : { [ state . searches . length - 1 ] : {
49
+ searches : { [ latestSearchIndex ] : {
50
+ planResponse : {
51
+ $set : {
52
+ error : action . payload
53
+ }
54
+ } ,
49
55
pending : { $set : false }
50
- } }
56
+ } } ,
57
+ activeSearch : { $set : latestSearchIndex }
51
58
} )
52
59
case 'PLAN_RESPONSE' :
53
- const latestIndex = state . searches . length - 1
54
60
return update ( state , {
55
- searches : { [ latestIndex ] : {
61
+ searches : { [ latestSearchIndex ] : {
56
62
planResponse : { $set : action . payload } ,
57
63
pending : { $set : false }
58
64
} } ,
59
- activeSearch : { $set : state . searches . length - 1 }
65
+ activeSearch : { $set : latestSearchIndex }
60
66
} )
61
67
case 'SET_ACTIVE_ITINERARY' :
62
68
if ( state . activeSearch !== null ) {
You can’t perform that action at this time.
0 commit comments