From f9e4a5079529cbc067dd21f2052993f1dda983cf Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 26 Jul 2020 22:15:57 +0530 Subject: [PATCH] Fix incorrect handling of non-JSON responses in APIs --- frontend/src/api/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 76b0367..2285f84 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -31,14 +31,16 @@ http.interceptors.response.use((resp) => { store.commit('setLoading', { model: resp.config.loading, status: false }); } - let data = { ...resp.data.data }; - if (!resp.config.preserveCase) { - if (resp.data && resp.data.data) { - if (typeof resp.data.data === 'object') { - // Transform field case. - data = humps.camelizeKeys(resp.data.data); - } + + let data = {}; + if (typeof resp.data.data === 'object') { + data = { ...resp.data.data }; + if (!resp.config.preserveCase) { + // Transform field case. + data = humps.camelizeKeys(resp.data.data); } + } else { + data = resp.data.data; } // Store the API response for a model. @@ -137,7 +139,8 @@ export const importSubscribers = (data) => http.post('/api/import/subscribers', export const getImportStatus = () => http.get('/api/import/subscribers'); -export const getImportLogs = () => http.get('/api/import/subscribers/logs'); +export const getImportLogs = async () => http.get('/api/import/subscribers/logs', + { preserveCase: true }); export const stopImport = () => http.delete('/api/import/subscribers');