Merge branch 'fix/error-on-account-creation' into 'develop'

Fix displaying multiple errors

Closes #159

See merge request pleroma/admin-fe!198
This commit is contained in:
Angelina Filippova 2021-03-01 22:38:25 +00:00
commit 6abb32e3e6
4 changed files with 32 additions and 13 deletions

View file

@ -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` - Fix wrapping `:icons` setting and parsing tuples in settings with key `:headers`
- Update keys for Pleroma.Web.Plugs.RemoteIp and PurgeExpiredActivity settings - 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 - 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 ## [2.2] - 2020-11-18
### Added ### Added

View file

@ -3,6 +3,19 @@ import Router from 'vue-router'
Vue.use(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 */ /* Layout */
import Layout from '@/views/layout/Layout' import Layout from '@/views/layout/Layout'

View file

@ -6,27 +6,32 @@ const service = axios.create({
timeout: 60000 // request timeout timeout: 60000 // request timeout
}) })
const isJson = ({ headers }) => headers['content-type'].includes('application/json')
// response interceptor // response interceptor
service.interceptors.response.use( service.interceptors.response.use(
response => response, response => response,
error => { error => {
let errorMessage
console.log(`Error ${error}`) console.log(`Error ${error}`)
if (error.response) { if (!error.response) {
const edata = error.response.data.error ? error.response.data.error : error.response.data Message({
errorMessage = !error.response.headers['content-type'].includes('application/json') message: error,
? `${error.message}` type: 'error',
: `${error.message} - ${edata}` duration: 5 * 1000
})
} else { } 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) return Promise.reject(error)
} }
) )

View file

@ -16,6 +16,7 @@ localVue.use(VueRouter)
localVue.use(Element) localVue.use(Element)
jest.mock('@/api/reports') jest.mock('@/api/reports')
jest.mock('@/api/settings')
describe('Log out', () => { describe('Log out', () => {
let store let store