commit: 52c22e863e66cd165adb100af42b88f5bbb116f0
parent 3e6309ef94c72770dc83cc53fd05f66e69538bc7
Author: Shpuld Shpuldson <shp@cock.li>
Date: Wed, 3 Feb 2021 12:02:37 +0200
Fix setting report state, add proper error handling
Diffstat:
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/src/i18n/en.json b/src/i18n/en.json
@@ -63,6 +63,7 @@
"more": "More",
"loading": "Loading…",
"generic_error": "An error occured",
+ "generic_error_message": "An error occured: {0}",
"error_retry": "Please try again",
"retry": "Try again",
"optional": "optional",
diff --git a/src/modules/reports.js b/src/modules/reports.js
@@ -41,7 +41,7 @@ const reports = {
closeUserReportingModal ({ commit }) {
commit('closeUserReportingModal')
},
- setReportState ({ commit, rootState }, { id, state }) {
+ setReportState ({ commit, dispatch, rootState }, { id, state }) {
const oldState = rootState.reports.reports[id].state
console.log(oldState, state)
commit('setReportState', { id, state })
@@ -49,8 +49,13 @@ const reports = {
console.log(report)
}).catch(e => {
console.error('Failed to set report state', e)
+ dispatch('pushGlobalNotice', {
+ level: 'error',
+ messageKey: 'general.generic_error_message',
+ messageArgs: [e.message],
+ timeout: 5000
+ })
commit('setReportState', { id, state: oldState })
- console.log(oldState)
})
},
addReport ({ commit }, report) {
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
@@ -1270,18 +1270,34 @@ const deleteChatMessage = ({ chatId, messageId, credentials }) => {
}
const setReportState = ({ id, state, credentials }) => {
- return promisedRequest({
- url: PLEROMA_ADMIN_REPORTS,
+ // Can't use promisedRequest because on OK this does not return json
+ return fetch(PLEROMA_ADMIN_REPORTS, {
+ headers: {
+ ...authHeaders(credentials),
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
method: 'PATCH',
- payload: {
- 'reports': [
- {
- id,
- state
- }
- ]
- }
+ body: JSON.stringify({
+ reports: [{
+ id,
+ state
+ }]
+ })
})
+ .then(data => {
+ if (data.status >= 500) {
+ throw Error(data.statusText)
+ } else if (data.status >= 400) {
+ return data.json()
+ }
+ return data
+ })
+ .then(data => {
+ if (data.errors) {
+ throw Error(data.errors[0].message)
+ }
+ })
}
const apiService = {