From a565ebf9cd1cbdababe6df3231ab972d74d0dadf Mon Sep 17 00:00:00 2001 From: mx1700 Date: Mon, 22 Jul 2019 22:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=B1=E7=BD=91=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 2 +- src/component/comment/commentInput.js | 2 +- src/component/comment/commentList.js | 1 - src/component/diary/diaryAction.js | 1 - src/component/diary/diaryIconOkB.js | 4 +-- src/component/diary/diaryList.js | 4 +-- src/component/follow/followUserList.js | 6 ++-- src/component/image/imageAction.js | 1 - src/component/notebook/notebookDiaryList.js | 4 +-- src/component/notebook/notebookList.js | 4 ++- .../notification/notificationList.js | 3 +- src/component/registerMobileForm.js | 1 - src/component/userIntro.js | 2 +- src/page/DiaryDetailPage.js | 4 +-- src/page/FeedbackPage.js | 1 - src/page/HomePage.js | 2 +- src/page/NotebookEditPage.js | 2 +- src/page/NotificationPage.js | 30 ++++++++----------- src/page/UserInfoEditPage.js | 2 +- src/page/UserIntroEditPage.js | 1 - src/page/UserNameEditPage.js | 1 - src/page/UserPage.js | 4 +-- src/page/WritePage.js | 10 +++---- src/util/api.js | 22 +++++++++----- 24 files changed, 55 insertions(+), 59 deletions(-) diff --git a/App.js b/App.js index 85ba986..056cbec 100644 --- a/App.js +++ b/App.js @@ -89,7 +89,7 @@ export default class App extends Component { .then(splash => { Navigation.setRoot(BottomNav.config(splash)); }) - .done(); + .catch((err) => console.log(err)) } render() { diff --git a/src/component/comment/commentInput.js b/src/component/comment/commentInput.js index 8081b47..35b15da 100644 --- a/src/component/comment/commentInput.js +++ b/src/component/comment/commentInput.js @@ -103,7 +103,7 @@ export default class CommentInput extends Component { .catch(e => { Alert.alert('回复失败'); }) - .done(() => { + .finally(() => { this.setState({comment_sending: false}); }); } diff --git a/src/component/comment/commentList.js b/src/component/comment/commentList.js index d24b944..9371919 100644 --- a/src/component/comment/commentList.js +++ b/src/component/comment/commentList.js @@ -120,7 +120,6 @@ export default class CommentList extends Component { .catch(e => { Msg.showMsg('删除失败'); }) - .done(); } }, { diff --git a/src/component/diary/diaryAction.js b/src/component/diary/diaryAction.js index ecd0e64..e11a73e 100644 --- a/src/component/diary/diaryAction.js +++ b/src/component/diary/diaryAction.js @@ -48,7 +48,6 @@ function action(componentId, diary, callbacks) { .catch(e => { Msg.showMsg('日记删除失败' + e.message); }) - .done(); }}, {text: '取消', onPress: () => {}}, ]); diff --git a/src/component/diary/diaryIconOkB.js b/src/component/diary/diaryIconOkB.js index 4fc3c8e..16f74f0 100644 --- a/src/component/diary/diaryIconOkB.js +++ b/src/component/diary/diaryIconOkB.js @@ -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() { diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 5056830..ffe9b40 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -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 }); diff --git a/src/component/follow/followUserList.js b/src/component/follow/followUserList.js index 7fd36e0..6750380 100644 --- a/src/component/follow/followUserList.js +++ b/src/component/follow/followUserList.js @@ -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 }); diff --git a/src/component/image/imageAction.js b/src/component/image/imageAction.js index 889ad91..c9d164e 100644 --- a/src/component/image/imageAction.js +++ b/src/component/image/imageAction.js @@ -49,7 +49,6 @@ function action(imageOption, maxSize, maxPixel, callback) { callback(e); }) - .done(); } }); } diff --git a/src/component/notebook/notebookDiaryList.js b/src/component/notebook/notebookDiaryList.js index 361d17a..dc7a7b9 100644 --- a/src/component/notebook/notebookDiaryList.js +++ b/src/component/notebook/notebookDiaryList.js @@ -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 }); diff --git a/src/component/notebook/notebookList.js b/src/component/notebook/notebookList.js index 0347c04..5236c01 100644 --- a/src/component/notebook/notebookList.js +++ b/src/component/notebook/notebookList.js @@ -107,7 +107,9 @@ export default class NotebookList extends Component { notebooks: groups }); - }).done(() => { + }) + .catch((err) => { console.error(err) }) + .finally(() => { this.setState({refreshing: false}); }); } diff --git a/src/component/notification/notificationList.js b/src/component/notification/notificationList.js index ed38c3b..77bc808 100644 --- a/src/component/notification/notificationList.js +++ b/src/component/notification/notificationList.js @@ -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); } } diff --git a/src/component/registerMobileForm.js b/src/component/registerMobileForm.js index df767c2..6101f8f 100644 --- a/src/component/registerMobileForm.js +++ b/src/component/registerMobileForm.js @@ -48,7 +48,6 @@ export default class RegisterMobileForm extends Component { .catch(e => { Msg.showMsg('验证码发送失败'); }) - .done(); }; async register() { diff --git a/src/component/userIntro.js b/src/component/userIntro.js index 9a612b2..6d4e000 100644 --- a/src/component/userIntro.js +++ b/src/component/userIntro.js @@ -44,7 +44,7 @@ export default class UserIntro extends Component { .catch(e => { Msg.showMsg('用户信息加载失败'); }) - .done(() => { + .finally(() => { this.setState({ isLoading: false }) diff --git a/src/page/DiaryDetailPage.js b/src/page/DiaryDetailPage.js index a426037..47a48b3 100644 --- a/src/page/DiaryDetailPage.js +++ b/src/page/DiaryDetailPage.js @@ -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') { diff --git a/src/page/FeedbackPage.js b/src/page/FeedbackPage.js index b9aa9f9..624032d 100644 --- a/src/page/FeedbackPage.js +++ b/src/page/FeedbackPage.js @@ -47,7 +47,6 @@ export default class FeedbackPage extends Component { .catch(e => { Msg.showMsg('反馈失败'); }) - .done(); } render() { diff --git a/src/page/HomePage.js b/src/page/HomePage.js index 28220ea..94ac2eb 100644 --- a/src/page/HomePage.js +++ b/src/page/HomePage.js @@ -194,7 +194,7 @@ export default class HomePage extends Component { this.setState({topic}); } }) - .done(); + .catch((err) => console.log(err)) } openTopicPage() { diff --git a/src/page/NotebookEditPage.js b/src/page/NotebookEditPage.js index 7db43d0..53dfb40 100644 --- a/src/page/NotebookEditPage.js +++ b/src/page/NotebookEditPage.js @@ -132,7 +132,7 @@ export default class NotebookEditPage extends Component { .catch(e => { Msg.showMsg('封面保存失败'); }) - .done(() => { + .finally(() => { this.setState({uploading: false}); }); } diff --git a/src/page/NotificationPage.js b/src/page/NotificationPage.js index 768749c..57fc5ac 100644 --- a/src/page/NotificationPage.js +++ b/src/page/NotificationPage.js @@ -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)) } diff --git a/src/page/UserInfoEditPage.js b/src/page/UserInfoEditPage.js index 2ac1f88..dec3c19 100644 --- a/src/page/UserInfoEditPage.js +++ b/src/page/UserInfoEditPage.js @@ -91,7 +91,7 @@ export default class UserInfoEditPage extends Component { .catch(e => { Msg.showMsg('头像更新失败:' + e.message); }) - .done(() => { + .finally(() => { this.setState({uploading: false}); }); } diff --git a/src/page/UserIntroEditPage.js b/src/page/UserIntroEditPage.js index f9bbc8f..088b536 100644 --- a/src/page/UserIntroEditPage.js +++ b/src/page/UserIntroEditPage.js @@ -87,7 +87,6 @@ export default class EditIntroPage extends Component { .catch(e => { Msg.showMsg('修改失败'); }) - .done(); } render() { diff --git a/src/page/UserNameEditPage.js b/src/page/UserNameEditPage.js index 88e89c4..51aada4 100644 --- a/src/page/UserNameEditPage.js +++ b/src/page/UserNameEditPage.js @@ -87,7 +87,6 @@ export default class UserNameEditPage extends Component { .catch(e => { Msg.showMsg('修改失败'); }) - .done(); } render() { diff --git a/src/page/UserPage.js b/src/page/UserPage.js index 73eadfe..c72cbf8 100644 --- a/src/page/UserPage.js +++ b/src/page/UserPage.js @@ -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, { diff --git a/src/page/WritePage.js b/src/page/WritePage.js index 33543be..be986d2 100644 --- a/src/page/WritePage.js +++ b/src/page/WritePage.js @@ -186,17 +186,17 @@ export default class WritePage extends Component { loadNotebook(resetTargetbook = false) { Api.getSelfNotebooks() .then(notebooks => { - if(!notebooks || !notebooks.filter) { + if (!notebooks || !notebooks.filter) { notebooks = []; } let unExpiredBooks = notebooks.filter(it => !it.isExpired); - if(unExpiredBooks.length > 0) { + if (unExpiredBooks.length > 0) { let st = { notebooks: unExpiredBooks } - if(resetTargetbook || this.state.targetbookId == 0) { + if (resetTargetbook || this.state.targetbookId == 0) { st.targetbookId = unExpiredBooks[0].id; st.targetbookSubject = unExpiredBooks[0].subject; } @@ -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() { diff --git a/src/util/api.js b/src/util/api.js index 999309d..4130594 100644 --- a/src/util/api.js +++ b/src/util/api.js @@ -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; }