Authored by 于良

优化HTTP错误处理,首页接口请求成功reducer修正 review by 盖剑秋

... ... @@ -104,9 +104,12 @@ class HomeContainer extends Component {
let brands = this.props.user.get('brands');
this.props.actions.switchBrand(brands.get(0).get('shopsId'), brands.get(0).get('shopName'));
}
console.log(this.props.home.brandId);
this.props.actions.overview(this.props.home.brandId);
this.props.actions.brandRank(this.props.home.brandId);
// this.props.actions.overview(1200);
// this.props.actions.brandRank(1200);
}
_onPressCategory(id) {
... ...
... ... @@ -59,20 +59,20 @@ export default function userReducer(state = initialState, action) {
}
case HOME_OVERVIEW_SUCCESS: {
let rise = Math.abs(action.payload.rankChange) == action.payload.rankChange ? true : false;
let nextState = state.set('isFetching', false)
.set('error', null)
.setIn(['overview', 'rank'], action.payload.rankNow)
.setIn(['overview', 'rise'], rise)
.setIn(['overview', 'riseCount'], Math.abs(action.payload.rankChange))
.setIn(['overview', 'goodsCount'], action.payload.buyNumbers)
.setIn(['overview', 'goodsAmount'], action.payload.orderAmount);
return nextState;
}
case HOME_BRABDRANK_SUCCESS: {
let rise = Math.abs(action.payload.rankChange) == action.payload.rankChange ? true : false;
let nextState = state.set('isFetching', false)
.set('error', null)
.setIn(['overview', 'goodsCount'], action.payload.buyNumbers)
.setIn(['overview', 'goodsAmount'], action.payload.orderAmount);
.setIn(['overview', 'rank'], action.payload.rankNow)
.setIn(['overview', 'rise'], rise)
.setIn(['overview', 'riseCount'], Math.abs(action.payload.rankChange))
return nextState;
}
... ...
... ... @@ -98,8 +98,9 @@ export default class Request {
throw({code: json.code, message: json.message});
}
} else {
let res = JSON.parse(response._bodyInit);
throw(res);
let error = new Error(response.statusText);
error.response = response;
throw(error);
}
}
... ...