Commit e492406af58cf118f1bb3896ae546d6b4c616fa5
1 parent
cbea4adc
feat: add alert&log for api 403
Showing
1 changed file
with
29 additions
and
4 deletions
front-end/h5/src/store/modules/work.js
| 1 | +import { notification } from 'ant-design-vue' | |
| 1 | 2 | import Element from 'core/models/element' |
| 2 | 3 | import strapi from '@/utils/strapi' |
| 3 | 4 | import Page from 'core/models/page' |
| ... | ... | @@ -10,6 +11,30 @@ function setLoading (commit, loadingName, isLoading) { |
| 10 | 11 | commit('loading/update', { type: loadingName, payload: isLoading }, { root: true }) |
| 11 | 12 | } |
| 12 | 13 | |
| 14 | +function handleError (error) { | |
| 15 | + if (error.message === 'Forbidden') { | |
| 16 | + console.log(` | |
| 17 | + ========================================================================================== | |
| 18 | + | |
| 19 | + #!zh: 接口 403,解决方案:https://github.com/ly525/luban-h5/discussions/110 | |
| 20 | + #!en: API 403 Forbidden, Solution: https://github.com/ly525/luban-h5/discussions/110 | |
| 21 | + | |
| 22 | + ========================================================================================== | |
| 23 | + `) | |
| 24 | + notification.warn( | |
| 25 | + { | |
| 26 | + message: 'API 403 Forbidden', | |
| 27 | + description: (h) => ( | |
| 28 | + <div style="text-align: left;"> | |
| 29 | + <div>- #!zh: 接口 403</div> | |
| 30 | + <div>- #!en: API 403 Forbidden</div> | |
| 31 | + <div>- <a href="https://github.com/ly525/luban-h5/discussions/110" target="_blank">#!en: solution(#!zh: 解决方案)</a></div> | |
| 32 | + </div> | |
| 33 | + ) | |
| 34 | + }) | |
| 35 | + } | |
| 36 | +} | |
| 37 | + | |
| 13 | 38 | export const actions = { |
| 14 | 39 | previewWork ({ commit }, payload = {}) { |
| 15 | 40 | commit('previewWork', payload) |
| ... | ... | @@ -23,7 +48,7 @@ export const actions = { |
| 23 | 48 | window.open(routeData.href, '_blank') |
| 24 | 49 | // 如果希望不打开新 tab,可以注释上面面两行,启用下面一行的代码即可,不过不推荐。将编辑器单独起一个页面更有利于 vuex 的数据管理 |
| 25 | 50 | // router.replace({ name: 'editor', params: { workId: entry.id } }) |
| 26 | - }) | |
| 51 | + }).catch(handleError) | |
| 27 | 52 | }, |
| 28 | 53 | updateWork ({ commit, state }, payload = {}) { |
| 29 | 54 | // update work with strapi |
| ... | ... | @@ -77,7 +102,7 @@ export const actions = { |
| 77 | 102 | loading_name: 'fetchWorks_loading', |
| 78 | 103 | successMsg: '获取作品列表成功', |
| 79 | 104 | customRequest: strapi.getEntries.bind(strapi) |
| 80 | - }).get('works', { is_template: false }) | |
| 105 | + }).get('works', { is_template: false }).catch(handleError) | |
| 81 | 106 | }, |
| 82 | 107 | fetchWorksWithForms ({ commit, dispatch, state }, workId) { |
| 83 | 108 | new AxiosWrapper({ |
| ... | ... | @@ -87,7 +112,7 @@ export const actions = { |
| 87 | 112 | loading_name: 'fetchWorks_loading', |
| 88 | 113 | successMsg: '获取作品列表成功', |
| 89 | 114 | customRequest: strapi.getEntries.bind(strapi) |
| 90 | - }).get('works/has-forms', { is_template: false }) | |
| 115 | + }).get('works/has-forms', { is_template: false }).catch(handleError) | |
| 91 | 116 | }, |
| 92 | 117 | fetchWorkTemplates ({ commit, dispatch, state }, workId) { |
| 93 | 118 | new AxiosWrapper({ |
| ... | ... | @@ -97,7 +122,7 @@ export const actions = { |
| 97 | 122 | loading_name: 'fetchWorkTemplates_loading', |
| 98 | 123 | successMsg: '获取模板列表成功', |
| 99 | 124 | customRequest: strapi.getEntries.bind(strapi) |
| 100 | - }).get('works', { is_template: true }) | |
| 125 | + }).get('works', { is_template: true }).catch(handleError) | |
| 101 | 126 | }, |
| 102 | 127 | /** |
| 103 | 128 | * | ... | ... |