From 5ca76701c2a24ded6181b93511ac9aa13a2387c1 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 2 Mar 2021 00:22:26 +0300 Subject: [PATCH 1/3] Fix displaying messages for multiple errors --- src/utils/request.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index b7e3d5f1..163ce872 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -6,27 +6,32 @@ const service = axios.create({ timeout: 60000 // request timeout }) +const isJson = ({ headers }) => headers['content-type'].includes('application/json') + // response interceptor service.interceptors.response.use( response => response, error => { - let errorMessage console.log(`Error ${error}`) - if (error.response) { - const edata = error.response.data.error ? error.response.data.error : error.response.data - errorMessage = !error.response.headers['content-type'].includes('application/json') - ? `${error.message}` - : `${error.message} - ${edata}` + if (!error.response) { + Message({ + message: error, + type: 'error', + duration: 5 * 1000 + }) } else { - errorMessage = error + const errors = Array.isArray(error.response.data) ? error.response.data : [error.response.data] + errors.forEach(errorData => { + const edata = errorData.error || errorData + Message({ + message: isJson(error.response) ? `${error.message} - ${edata}` : `${error.message}`, + type: 'error', + duration: 5 * 1000 + }) + }) } - Message({ - message: errorMessage, - type: 'error', - duration: 5 * 1000 - }) return Promise.reject(error) } ) From 6722a9e34ae4b8d6b86adfc699670a15b31e76ef Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 8 Feb 2021 01:42:31 +0300 Subject: [PATCH 2/3] Replace router push with the one that catches errors --- src/router/index.js | 13 +++++++++++++ test/views/layout/index.test.js | 1 + 2 files changed, 14 insertions(+) diff --git a/src/router/index.js b/src/router/index.js index 661fb7f2..d151daeb 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,6 +3,19 @@ import Router from 'vue-router' Vue.use(Router) +const originalPush = Router.prototype.push +Router.prototype.push = function push(location, onResolve, onReject) { + if (onResolve || onReject) { return originalPush.call(this, location, onResolve, onReject) } + return originalPush.call(this, location).catch((err) => { + if (Router.isNavigationFailure(err)) { + // resolve err + return err + } + // rethrow error + return Promise.reject(err) + }) +} + /* Layout */ import Layout from '@/views/layout/Layout' diff --git a/test/views/layout/index.test.js b/test/views/layout/index.test.js index 686a4226..af71ee17 100644 --- a/test/views/layout/index.test.js +++ b/test/views/layout/index.test.js @@ -16,6 +16,7 @@ localVue.use(VueRouter) localVue.use(Element) jest.mock('@/api/reports') +jest.mock('@/api/settings') describe('Log out', () => { let store From c6169f36f7f118da465b772f96d30e1d02dd2bc1 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 2 Mar 2021 00:30:35 +0300 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac48d297..c80c1793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix wrapping `:icons` setting and parsing tuples in settings with key `:headers` - Update keys for Pleroma.Web.Plugs.RemoteIp and PurgeExpiredActivity settings - Update switching between local and remote emoji packs panels: the panel with the pack's metadata will be closed when another panel is opened - +- Fix displaying messages for multiple errors ## [2.2] - 2020-11-18 ### Added