修复弱网崩溃问题

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 => { .then(splash => {
Navigation.setRoot(BottomNav.config(splash)); Navigation.setRoot(BottomNav.config(splash));
}) })
.done(); .catch((err) => console.log(err))
} }
render() { render() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -67,18 +67,18 @@ export default class NotificationPage extends Component {
componentDidMount() { componentDidMount() {
InteractionManager.runAfterInteractions(() => { InteractionManager.runAfterInteractions(() => {
if (Platform.OS === 'android') { if (Platform.OS === 'android') {
this.initAndroid().done() this.initAndroid().catch((err) => console.log(err))
} else { } 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.loginListener = DeviceEventEmitter.addListener(Event.login, () => {
this.registerUser().done(); this.registerUser().catch((err) => console.log(err))
this.restartTipTimer().done(); this.restartTipTimer().catch((err) => console.log(err))
}); });
this.updatePushInfo().done(); this.updatePushInfo();
} }
componentWillUnmount() { componentWillUnmount() {
@ -86,14 +86,8 @@ export default class NotificationPage extends Component {
//todo:删除 push 事件注册,删除定时器 //todo:删除 push 事件注册,删除定时器
} }
async updatePushInfo() { updatePushInfo() {
let info; Api.updatePushInfo().catch((err) => console.log(err))
try {
info = await Api.updatePushInfo()
} catch (err) {
console.error(err)
}
// console.log('updatePushInfo', info)
} }
/** /**
@ -115,7 +109,7 @@ export default class NotificationPage extends Component {
console.log("push init: " + msg); console.log("push init: " + msg);
this.registerUser(); this.registerUser();
Push.addReceiveNotificationListener((msg) => { 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); console.log("push init: " + msg);
this.registerUser(); this.registerUser();
Push.addReceiveNotificationListener((msg) => { Push.addReceiveNotificationListener((msg) => {
this.restartTipTimer().done(); this.restartTipTimer().catch((err) => console.log(err))
}); });
}) })
} }
@ -153,7 +147,7 @@ export default class NotificationPage extends Component {
_onRefresh() { _onRefresh() {
console.log(this.props.componentId); console.log(this.props.componentId);
this.restartTipTimer().done(); this.restartTipTimer().catch((err) => console.log(err))
} }
_onRefreshed(msgCount) { _onRefreshed(msgCount) {
@ -174,7 +168,7 @@ export default class NotificationPage extends Component {
} }
_onDeletePress(msg) { _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 => { .catch(e => {
Msg.showMsg('头像更新失败:' + e.message); Msg.showMsg('头像更新失败:' + e.message);
}) })
.done(() => { .finally(() => {
this.setState({uploading: false}); this.setState({uploading: false});
}); });
} }

View file

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

View file

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

View file

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

View file

@ -186,17 +186,17 @@ export default class WritePage extends Component {
loadNotebook(resetTargetbook = false) { loadNotebook(resetTargetbook = false) {
Api.getSelfNotebooks() Api.getSelfNotebooks()
.then(notebooks => { .then(notebooks => {
if(!notebooks || !notebooks.filter) { if (!notebooks || !notebooks.filter) {
notebooks = []; notebooks = [];
} }
let unExpiredBooks = notebooks.filter(it => !it.isExpired); let unExpiredBooks = notebooks.filter(it => !it.isExpired);
if(unExpiredBooks.length > 0) { if (unExpiredBooks.length > 0) {
let st = { let st = {
notebooks: unExpiredBooks notebooks: unExpiredBooks
} }
if(resetTargetbook || this.state.targetbookId == 0) { if (resetTargetbook || this.state.targetbookId == 0) {
st.targetbookId = unExpiredBooks[0].id; st.targetbookId = unExpiredBooks[0].id;
st.targetbookSubject = unExpiredBooks[0].subject; st.targetbookSubject = unExpiredBooks[0].subject;
} }
@ -204,7 +204,8 @@ export default class WritePage extends Component {
this.setState(st); this.setState(st);
} }
}).done(); })
.catch((err) => { console.error(err) })
} }
_onPickPhoto() { _onPickPhoto() {
@ -300,7 +301,6 @@ export default class WritePage extends Component {
Msg.hideMsg(waitingToast); Msg.hideMsg(waitingToast);
Msg.showMsg('保存失败'); Msg.showMsg('保存失败');
}) })
.done();
} }
render() { render() {

View file

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