Skip to content

Commit

Permalink
feat: add alert&log for api 403
Browse files Browse the repository at this point in the history
  • Loading branch information
ly525 committed Oct 14, 2020
1 parent cbea4ad commit e492406
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions front-end/h5/src/store/modules/work.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { notification } from 'ant-design-vue'
import Element from 'core/models/element'
import strapi from '@/utils/strapi'
import Page from 'core/models/page'
Expand All @@ -10,6 +11,30 @@ function setLoading (commit, loadingName, isLoading) {
commit('loading/update', { type: loadingName, payload: isLoading }, { root: true })
}

function handleError (error) {
if (error.message === 'Forbidden') {
console.log(`
==========================================================================================
#!zh: 接口 403,解决方案:https://github.com/ly525/luban-h5/discussions/110
#!en: API 403 Forbidden, Solution: https://github.com/ly525/luban-h5/discussions/110
==========================================================================================
`)
notification.warn(
{
message: 'API 403 Forbidden',
description: (h) => (
<div style="text-align: left;">
<div>- #!zh: 接口 403</div>
<div>- #!en: API 403 Forbidden</div>
<div>- <a href="https://github.com/ly525/luban-h5/discussions/110" target="_blank">#!en: solution(#!zh: 解决方案)</a></div>
</div>
)
})
}
}

export const actions = {
previewWork ({ commit }, payload = {}) {
commit('previewWork', payload)
Expand All @@ -23,7 +48,7 @@ export const actions = {
window.open(routeData.href, '_blank')
// 如果希望不打开新 tab,可以注释上面面两行,启用下面一行的代码即可,不过不推荐。将编辑器单独起一个页面更有利于 vuex 的数据管理
// router.replace({ name: 'editor', params: { workId: entry.id } })
})
}).catch(handleError)
},
updateWork ({ commit, state }, payload = {}) {
// update work with strapi
Expand Down Expand Up @@ -77,7 +102,7 @@ export const actions = {
loading_name: 'fetchWorks_loading',
successMsg: '获取作品列表成功',
customRequest: strapi.getEntries.bind(strapi)
}).get('works', { is_template: false })
}).get('works', { is_template: false }).catch(handleError)
},
fetchWorksWithForms ({ commit, dispatch, state }, workId) {
new AxiosWrapper({
Expand All @@ -87,7 +112,7 @@ export const actions = {
loading_name: 'fetchWorks_loading',
successMsg: '获取作品列表成功',
customRequest: strapi.getEntries.bind(strapi)
}).get('works/has-forms', { is_template: false })
}).get('works/has-forms', { is_template: false }).catch(handleError)
},
fetchWorkTemplates ({ commit, dispatch, state }, workId) {
new AxiosWrapper({
Expand All @@ -97,7 +122,7 @@ export const actions = {
loading_name: 'fetchWorkTemplates_loading',
successMsg: '获取模板列表成功',
customRequest: strapi.getEntries.bind(strapi)
}).get('works', { is_template: true })
}).get('works', { is_template: true }).catch(handleError)
},
/**
*
Expand Down

0 comments on commit e492406

Please sign in to comment.