|
@@ -3,6 +3,15 @@ import { $BRIDGE } from '../../core/bridge'
|
|
|
|
|
|
let action = null
|
|
|
|
|
|
+// 自定义异常上报
|
|
|
+function sendErrorLog (content, options) {
|
|
|
+ if (window.Sentry && typeof window.Sentry.captureMessage === 'function') {
|
|
|
+ Sentry.captureMessage(content, options)
|
|
|
+ } else if (window.__WORK_SENTRY__ && typeof window.__WORK_SENTRY__.captureMessage === 'function') {
|
|
|
+ window.__WORK_SENTRY__.captureMessage(content, options)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export default {
|
|
|
namespaced: true,
|
|
|
state: () => ({
|
|
@@ -56,12 +65,46 @@ export default {
|
|
|
})
|
|
|
|
|
|
start({
|
|
|
+ async fetch(url, ...args) {
|
|
|
+ const isImage = /\.(png|jpe?g|gif|svg|webp|ico)$/i.test(url);
|
|
|
+ try {
|
|
|
+ return await window.fetch(url, ...args);
|
|
|
+ } catch (err) {
|
|
|
+ if (isImage) {
|
|
|
+ console.warn('Image fetch failed but ignored:', url);
|
|
|
+ sendErrorLog(new Error(`Image fetch failed but ignored`), {
|
|
|
+ level: 'error',
|
|
|
+ tags: {
|
|
|
+ href: location.href,
|
|
|
+ url: url
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 返回一个空响应或占位图,避免子应用报错
|
|
|
+ return new Response(new Blob(), { status: 200 });
|
|
|
+ }
|
|
|
+ console.error('Fetch failed for:', url, err);
|
|
|
+ sendErrorLog(new Error(`Qiankun Fetch failed`), {
|
|
|
+ level: 'error',
|
|
|
+ tags: {
|
|
|
+ href: location.href,
|
|
|
+ url: url
|
|
|
+ }
|
|
|
+ })
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ },
|
|
|
sandbox: {
|
|
|
strictStyleIsolation: true
|
|
|
}
|
|
|
})
|
|
|
addGlobalUncaughtErrorHandler((event) => {
|
|
|
const isSubAppLoadError = event.type === 'error' && event.message.indexOf('died in status LOADING_SOURCE_CODE') !== -1
|
|
|
+ sendErrorLog(new Error(`SubApp Load ERROR`), {
|
|
|
+ level: 'error',
|
|
|
+ tags: {
|
|
|
+ href: location.href
|
|
|
+ }
|
|
|
+ })
|
|
|
commit('toggleLoading', false)
|
|
|
if (isSubAppLoadError) {
|
|
|
commit('toggleAbnormal', {
|