修复弱网崩溃问题

This commit is contained in:
mx1700 2019-07-22 22:29:17 +08:00
parent b1a05f1780
commit a565ebf9cd
24 changed files with 55 additions and 59 deletions

2
App.js
View file

@ -89,7 +89,7 @@ export default class App extends Component {
.then(splash => {
Navigation.setRoot(BottomNav.config(splash));
})
.done();
.catch((err) => console.log(err))
}
render() {

View file

@ -103,7 +103,7 @@ export default class CommentInput extends Component {
.catch(e => {
Alert.alert('回复失败');
})
.done(() => {
.finally(() => {
this.setState({comment_sending: false});
});
}

View file

@ -120,7 +120,6 @@ export default class CommentList extends Component {
.catch(e => {
Msg.showMsg('删除失败');
})
.done();
}
},
{

View file

@ -48,7 +48,6 @@ function action(componentId, diary, callbacks) {
.catch(e => {
Msg.showMsg('日记删除失败' + e.message);
})
.done();
}},
{text: '取消', onPress: () => {}},
]);

View file

@ -56,8 +56,7 @@ export default class DiaryIconOkB extends Component {
if(result) {
this.refreshBack(result);
}
})
.done();
}).catch((err) => console.log(err))
} else {
DeviceEventEmitter.emit(Event.updateDiarys);
@ -66,7 +65,6 @@ export default class DiaryIconOkB extends Component {
.catch(e => {
Msg.showMsg('操作失败');
})
.done();
}
render() {

View file

@ -164,7 +164,7 @@ export default class DiaryList extends Component {
refreshFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
mounting: false,
refreshing: false
@ -199,7 +199,7 @@ export default class DiaryList extends Component {
loadFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
loadingMore: false
});

View file

@ -64,7 +64,7 @@ export default class FollowUserList extends Component {
Alert.alert('提示', '确定删除关注?', [
{text: '删除', style: 'destructive', onPress: () => {
this.props.onDeletePress(user.id)
.done(() => {
.finally(() => {
let filterUsers = this.state.users.filter((it) => it.id !== user.id);
this.setState({
users: filterUsers
@ -103,7 +103,7 @@ export default class FollowUserList extends Component {
refreshFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
refreshing: false
});
@ -139,7 +139,7 @@ export default class FollowUserList extends Component {
loadFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
loadingMore: false
});

View file

@ -49,7 +49,6 @@ function action(imageOption, maxSize, maxPixel, callback) {
callback(e);
})
.done();
}
});
}

View file

@ -131,7 +131,7 @@ export default class NotebookDiaryList extends Component {
refreshFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
mounting: false,
refreshing: false
@ -169,7 +169,7 @@ export default class NotebookDiaryList extends Component {
loadFailed: true
});
}).done(() => {
}).finally(() => {
this.setState({
loadingMore: false
});

View file

@ -107,7 +107,9 @@ export default class NotebookList extends Component {
notebooks: groups
});
}).done(() => {
})
.catch((err) => { console.error(err) })
.finally(() => {
this.setState({refreshing: false});
});
}

View file

@ -36,7 +36,6 @@ export default class NotificationList extends Component {
let notifications = await this.getMessages();
this.notificationsData = notifications;
this.setNotifications(notifications);
this.props.onRefreshed && this.props.onRefreshed(notifications.length);
} catch (e) {
this.setState({error: true});
}
@ -74,6 +73,8 @@ export default class NotificationList extends Component {
this.setState({
notifications: reducedNoti
});
this.props.onRefreshed && this.props.onRefreshed(notifications.length);
}
}

View file

@ -48,7 +48,6 @@ export default class RegisterMobileForm extends Component {
.catch(e => {
Msg.showMsg('验证码发送失败');
})
.done();
};
async register() {

View file

@ -44,7 +44,7 @@ export default class UserIntro extends Component {
.catch(e => {
Msg.showMsg('用户信息加载失败');
})
.done(() => {
.finally(() => {
this.setState({
isLoading: false
})

View file

@ -93,7 +93,7 @@ export default class DiaryDetailPage extends Component {
}, (index) => {
if(index == 0) {
Api.report(this.state.diary.user_id, this.state.diary.id).done();
Api.report(this.state.diary.user_id, this.state.diary.id).catch((err) => console.log(err))
Msg.showMsg('举报成功,感谢你的贡献 :)');
}
});
@ -110,7 +110,7 @@ export default class DiaryDetailPage extends Component {
this.refreshDiary(this.state.diary);
});
}).done();
}).catch((err) => console.log(err))
this.diaryListener = DeviceEventEmitter.addListener(Event.updateDiarys, (param) => {
if(param != 'del') {

View file

@ -47,7 +47,6 @@ export default class FeedbackPage extends Component {
.catch(e => {
Msg.showMsg('反馈失败');
})
.done();
}
render() {

View file

@ -194,7 +194,7 @@ export default class HomePage extends Component {
this.setState({topic});
}
})
.done();
.catch((err) => console.log(err))
}
openTopicPage() {

View file

@ -132,7 +132,7 @@ export default class NotebookEditPage extends Component {
.catch(e => {
Msg.showMsg('封面保存失败');
})
.done(() => {
.finally(() => {
this.setState({uploading: false});
});
}

View file

@ -67,18 +67,18 @@ export default class NotificationPage extends Component {
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
if (Platform.OS === 'android') {
this.initAndroid().done()
this.initAndroid().catch((err) => console.log(err))
} else {
this.initIOS().done()
this.initIOS().catch((err) => console.log(err))
}
this.restartTipTimer().done();
this.restartTipTimer().catch((err) => console.log(err))
});
this.loginListener = DeviceEventEmitter.addListener(Event.login, () => {
this.registerUser().done();
this.restartTipTimer().done();
this.registerUser().catch((err) => console.log(err))
this.restartTipTimer().catch((err) => console.log(err))
});
this.updatePushInfo().done();
this.updatePushInfo();
}
componentWillUnmount() {
@ -86,14 +86,8 @@ export default class NotificationPage extends Component {
//todo:删除 push 事件注册,删除定时器
}
async updatePushInfo() {
let info;
try {
info = await Api.updatePushInfo()
} catch (err) {
console.error(err)
}
// console.log('updatePushInfo', info)
updatePushInfo() {
Api.updatePushInfo().catch((err) => console.log(err))
}
/**
@ -115,7 +109,7 @@ export default class NotificationPage extends Component {
console.log("push init: " + msg);
this.registerUser();
Push.addReceiveNotificationListener((msg) => {
this.restartTipTimer().done();
this.restartTipTimer().catch((err) => console.log(err))
});
})
}
@ -125,7 +119,7 @@ export default class NotificationPage extends Component {
console.log("push init: " + msg);
this.registerUser();
Push.addReceiveNotificationListener((msg) => {
this.restartTipTimer().done();
this.restartTipTimer().catch((err) => console.log(err))
});
})
}
@ -153,7 +147,7 @@ export default class NotificationPage extends Component {
_onRefresh() {
console.log(this.props.componentId);
this.restartTipTimer().done();
this.restartTipTimer().catch((err) => console.log(err))
}
_onRefreshed(msgCount) {
@ -174,7 +168,7 @@ export default class NotificationPage extends Component {
}
_onDeletePress(msg) {
this._setRead(msg).done();
this._setRead(msg).catch((err) => console.log(err))
}

View file

@ -91,7 +91,7 @@ export default class UserInfoEditPage extends Component {
.catch(e => {
Msg.showMsg('头像更新失败:' + e.message);
})
.done(() => {
.finally(() => {
this.setState({uploading: false});
});
}

View file

@ -87,7 +87,6 @@ export default class EditIntroPage extends Component {
.catch(e => {
Msg.showMsg('修改失败');
})
.done();
}
render() {

View file

@ -87,7 +87,6 @@ export default class UserNameEditPage extends Component {
.catch(e => {
Msg.showMsg('修改失败');
})
.done();
}
render() {

View file

@ -94,7 +94,7 @@ export default class UserPage extends Component {
})
.catch(e => {
Alert.alert('关注失败');
}).done();
})
} else if(buttonId == 'navButtonFollowSelected') {
Api.deleteFollow(this.userId)
@ -112,7 +112,7 @@ export default class UserPage extends Component {
})
.catch(e => {
Alert.alert('取消关注失败');
}).done();
})
} else if(buttonId == 'setting') {
Navigation.push(this.props.componentId, {

View file

@ -204,7 +204,8 @@ export default class WritePage extends Component {
this.setState(st);
}
}).done();
})
.catch((err) => { console.error(err) })
}
_onPickPhoto() {
@ -300,7 +301,6 @@ export default class WritePage extends Component {
Msg.hideMsg(waitingToast);
Msg.showMsg('保存失败');
})
.done();
}
render() {

View file

@ -378,7 +378,10 @@ async function upload(method, api, body) {
})
.then(checkStatus)
.then(parseJSON)
.catch(handleCatch)
.catch((err) => {
err.message += ' api:' + api;
handleCatch(err);
})
, 60000);
}
@ -400,8 +403,10 @@ async function call(method, api, body = null, _timeout = 10000) {
})
.then(checkStatus)
.then(parseJSON)
.catch(handleCatch)
.catch((err) => {
err.message += ' api:' + api;
handleCatch(err);
})
, _timeout);
}
@ -425,8 +430,10 @@ async function callV2(method, api, body = null, _timeout = 10000) {
})
.then(checkStatus)
.then(parseJSON)
.catch(handleCatch)
.catch((err) => {
err.message += ' api:' + api;
handleCatch(err);
})
,_timeout);
}
@ -475,8 +482,9 @@ function parseJSON(response) {
}
function handleCatch(err) {
if (err.message === 'Network request failed') {
throw new Error('网络连接失败', err.id)
if (err.message.indexOf('Network request failed') >= 0) {
err.message = err.message.replace('Network request failed', '网络连接失败');
throw err;
} else {
throw err;
}