提交 79a43be0 编写于 作者: fxy060608's avatar fxy060608

fix(core): onError

上级 307ecfb4
...@@ -13374,7 +13374,7 @@ function weexGetSystemInfoSync() { ...@@ -13374,7 +13374,7 @@ function weexGetSystemInfoSync() {
} }
const getDeviceInfo = defineSyncApi('getDeviceInfo', () => { const getDeviceInfo = defineSyncApi('getDeviceInfo', () => {
weexGetSystemInfoSync(); weexGetSystemInfoSync();
const { deviceBrand, deviceModel, osName, osVersion, deviceOrientation, deviceType, } = systemInfo; const { deviceBrand = '', deviceModel, osName, osVersion, deviceOrientation, deviceType, } = systemInfo;
const brand = deviceBrand.toLowerCase(); const brand = deviceBrand.toLowerCase();
const _osName = osName.toLowerCase(); const _osName = osName.toLowerCase();
return { return {
...@@ -14069,17 +14069,17 @@ const getImageInfo = defineAsyncApi(API_GET_IMAGE_INFO, (options, { resolve, rej ...@@ -14069,17 +14069,17 @@ const getImageInfo = defineAsyncApi(API_GET_IMAGE_INFO, (options, { resolve, rej
const getVideoInfo = defineAsyncApi(API_GET_VIDEO_INFO, (options, { resolve, reject }) => { const getVideoInfo = defineAsyncApi(API_GET_VIDEO_INFO, (options, { resolve, reject }) => {
plus.io.getVideoInfo({ plus.io.getVideoInfo({
filePath: options.src, filePath: options.src,
success: (data) => { success: (videoInfo) => {
return { resolve({
orientation: data.orientation, orientation: videoInfo.orientation,
type: data.type, type: videoInfo.type,
duration: data.duration, duration: videoInfo.duration,
size: data.size, size: videoInfo.size,
height: data.height, height: videoInfo.height,
width: data.width, width: videoInfo.width,
fps: data.fps || 30, fps: videoInfo.fps || 30,
bitrate: data.bitrate, bitrate: videoInfo.bitrate,
}; });
}, },
fail: warpPlusErrorCallback(reject), fail: warpPlusErrorCallback(reject),
}); });
......
import { isString, isArray, isFunction } from '@vue/shared'; import { isString, isArray, isFunction } from '@vue/shared';
import { invokeArrayFns, ON_LOAD, ON_SHOW, LINEFEED, RENDERJS_MODULES, WXS_PROTOCOL, formatLog, WXS_MODULES, UniLifecycleHooks, ON_ERROR, invokeCreateVueAppHook } from '@dcloudio/uni-shared'; import { invokeArrayFns, ON_LOAD, ON_SHOW, LINEFEED, RENDERJS_MODULES, WXS_PROTOCOL, formatLog, WXS_MODULES, ON_ERROR, UniLifecycleHooks, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
import { injectHook } from 'vue'; import { injectHook } from 'vue';
function getCurrentPage() { function getCurrentPage() {
...@@ -148,17 +148,19 @@ function set(target, key, val) { ...@@ -148,17 +148,19 @@ function set(target, key, val) {
return (target[key] = val); return (target[key] = val);
} }
function errorHandler(err, instance, info) { function createErrorHandler(app) {
if (!instance) { return function errorHandler(err, instance, _info) {
throw err; if (!instance) {
} throw err;
const app = getApp(); }
if (!app || !app.$vm) { const appInstance = app._instance;
throw err; if (!appInstance || !appInstance.proxy) {
} throw err;
{ }
invokeHook(app.$vm, ON_ERROR, err); {
} invokeHook(appInstance.proxy.$vm, ON_ERROR, err);
}
};
} }
function mergeAsArray(to, from) { function mergeAsArray(to, from) {
return to ? [...new Set([].concat(to, from))] : from; return to ? [...new Set([].concat(to, from))] : from;
...@@ -254,7 +256,7 @@ function uniIdMixin(globalProperties) { ...@@ -254,7 +256,7 @@ function uniIdMixin(globalProperties) {
function initApp(app) { function initApp(app) {
const appConfig = app._context.config; const appConfig = app._context.config;
if (isFunction(app._component.onError)) { if (isFunction(app._component.onError)) {
appConfig.errorHandler = errorHandler; appConfig.errorHandler = createErrorHandler(app);
} }
initOptionMergeStrategies(appConfig.optionMergeStrategies); initOptionMergeStrategies(appConfig.optionMergeStrategies);
const globalProperties = appConfig.globalProperties; const globalProperties = appConfig.globalProperties;
......
...@@ -2,7 +2,7 @@ declare module '@vue/runtime-core' { ...@@ -2,7 +2,7 @@ declare module '@vue/runtime-core' {
interface ComponentCustomProperties { interface ComponentCustomProperties {
$vm: ComponentPublicInstance $vm: ComponentPublicInstance
globalData: Record<string, any> globalData: Record<string, any>
$callHook: (hook: string, args?: unknown) => unknown $callHook: (hook: string, args?: unknown, extras?: unknown) => unknown
$callCreatedHook: () => void $callCreatedHook: () => void
} }
} }
......
import { invokeHook } from '@dcloudio/uni-core' import { invokeHook } from '@dcloudio/uni-core'
import { ON_ERROR, UniLifecycleHooks } from '@dcloudio/uni-shared' import { ON_ERROR, UniLifecycleHooks } from '@dcloudio/uni-shared'
import { AppConfig, ComponentPublicInstance } from 'vue' import { App, AppConfig, ComponentPublicInstance } from 'vue'
export function errorHandler( export function createErrorHandler(app: App) {
err: unknown, return function errorHandler(
instance: ComponentPublicInstance | null, err: unknown,
info: string instance: ComponentPublicInstance | null,
) { _info: string
if (!instance) { ) {
throw err if (!instance) {
} throw err
const app = getApp() }
if (!app || !app.$vm) { const appInstance = app._instance
throw err if (!appInstance || !appInstance.proxy) {
} throw err
if (__PLATFORM__ !== 'h5' && __PLATFORM__ !== 'app') { }
app.$vm.$callHook(ON_ERROR, err, info) if (__PLATFORM__ !== 'h5' && __PLATFORM__ !== 'app') {
} else { appInstance.proxy.$vm.$callHook(ON_ERROR, err)
invokeHook(app.$vm, ON_ERROR, err) } else {
invokeHook(appInstance.proxy.$vm, ON_ERROR, err)
}
} }
} }
......
...@@ -5,13 +5,13 @@ import { invokeCreateVueAppHook } from '@dcloudio/uni-shared' ...@@ -5,13 +5,13 @@ import { invokeCreateVueAppHook } from '@dcloudio/uni-shared'
import { applyOptions } from './componentOptions' import { applyOptions } from './componentOptions'
import { set } from './componentInstance' import { set } from './componentInstance'
import { errorHandler, initOptionMergeStrategies } from './appConfig' import { createErrorHandler, initOptionMergeStrategies } from './appConfig'
import { uniIdMixin } from './uni-id-mixin' import { uniIdMixin } from './uni-id-mixin'
export function initApp(app: App) { export function initApp(app: App) {
const appConfig = app._context.config const appConfig = app._context.config
if (isFunction((app._component as any).onError)) { if (isFunction((app._component as any).onError)) {
appConfig.errorHandler = errorHandler appConfig.errorHandler = createErrorHandler(app)
} }
initOptionMergeStrategies(appConfig.optionMergeStrategies) initOptionMergeStrategies(appConfig.optionMergeStrategies)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册