aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2021-02-03 12:02:37 +0200
committerShpuld Shpuldson <shp@cock.li>2021-02-03 12:02:37 +0200
commit52c22e863e66cd165adb100af42b88f5bbb116f0 (patch)
treef9230fb6f056b59140477775c9e232dc2ff453f1 /src
parent3e6309ef94c72770dc83cc53fd05f66e69538bc7 (diff)
Fix setting report state, add proper error handling
Diffstat (limited to 'src')
-rw-r--r--src/i18n/en.json1
-rw-r--r--src/modules/reports.js9
-rw-r--r--src/services/api/api.service.js36
3 files changed, 34 insertions, 12 deletions
diff --git a/src/i18n/en.json b/src/i18n/en.json
index cea2a12d..3bdd42e3 100644
--- 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
index 93866e20..b25e9ee9 100644
--- 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
index 9bc90887..e60010fe 100644
--- 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 = {