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

fix(core): onError

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