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 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/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) } ) 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