From 1229622fedf4401f2ce2e5aa6741de3a8b1291a3 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 24 Apr 2019 16:19:27 -0400 Subject: [PATCH] refactor error handling of pinStatus --- src/components/extra_buttons/extra_buttons.js | 7 ++----- src/modules/statuses.js | 8 ++------ src/services/api/api.service.js | 10 ++++------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/components/extra_buttons/extra_buttons.js b/src/components/extra_buttons/extra_buttons.js index 55a4caad..51892d0d 100644 --- a/src/components/extra_buttons/extra_buttons.js +++ b/src/components/extra_buttons/extra_buttons.js @@ -24,11 +24,8 @@ const ExtraButtons = { }, pinStatus () { this.refreshPopper() - this.$store.dispatch('pinStatus', this.status.id).then((status) => { - if (status.error) { - this.$emit('onError', status.error) - } - }) + this.$store.dispatch('pinStatus', this.status.id) + .catch(err => this.$emit('onError', err.error.error)) }, unpinStatus () { this.refreshPopper() diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 9b4eb0f7..b3d6802c 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -546,12 +546,8 @@ const statuses = { .then(statuses => dispatch('addNewStatuses', { statuses, timeline: 'user', userId })) }, pinStatus ({ rootState, commit }, statusId) { - return rootState.api.backendInteractor.pinOwnStatus(statusId).then((status) => { - if (!status.error) { - commit('setPinned', { status }) - } - return status - }) + return rootState.api.backendInteractor.pinOwnStatus(statusId) + .then((status) => commit('setPinned', { status })) }, unpinStatus ({ rootState, commit }, statusId) { rootState.api.backendInteractor.unpinOwnStatus(statusId) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 03137d20..86fb6365 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -213,19 +213,17 @@ const unfollowUser = ({id, credentials}) => { } const pinOwnStatus = ({ id, credentials }) => { - let url = MASTODON_PIN_OWN_STATUS(id) - return fetch(url, { + return promisedRequest(MASTODON_PIN_OWN_STATUS(id), { headers: authHeaders(credentials), method: 'POST' - }).then((data) => data.json()) + }) } const unpinOwnStatus = ({ id, credentials }) => { - let url = MASTODON_UNPIN_OWN_STATUS(id) - return fetch(url, { + return promisedRequest(MASTODON_UNPIN_OWN_STATUS(id), { headers: authHeaders(credentials), method: 'POST' - }).then((data) => data.json()) + }) } const blockUser = ({id, credentials}) => {