提交 ccc53ef5 编写于 作者: DCloud-yyl's avatar DCloud-yyl

uni-exit优化UniError实现

上级 8d5ce000
import { ExitOptions, ExitFailCallback, ExitCompleteCallback, Exit} from "../interface.uts" import { ExitOptions, ExitFailCallback, ExitCompleteCallback, Exit} from "../interface.uts"
import { UniErrorSubject, UniErrors } from "../unierror.uts" import { ExitFailImpl } from "../unierror.uts"
/** /**
...@@ -7,7 +7,7 @@ import { UniErrorSubject, UniErrors } from "../unierror.uts" ...@@ -7,7 +7,7 @@ import { UniErrorSubject, UniErrors } from "../unierror.uts"
* iOS平台不支持,触发错误回调 * iOS平台不支持,触发错误回调
*/ */
export const exit : Exit = function (options: ExitOptions | null) { export const exit : Exit = function (options: ExitOptions | null) {
let err = new UniError(UniErrorSubject, 12001, UniErrors.get(12001)!); let err = new ExitFailImpl(12001);
options?.fail?.(err) options?.fail?.(err)
options?.complete?.(err) options?.complete?.(err)
} }
...@@ -5,6 +5,21 @@ export type ExitSuccess = { ...@@ -5,6 +5,21 @@ export type ExitSuccess = {
errMsg: string errMsg: string
} }
/**
* 错误码
* - 12001: 系统不支持
* - 12002: 未知错误
*/
export type ExitErrorCode = 12001 | 12002
/**
* uni.exit失败回调参数
*/
export interface IExitError extends IUniError {
errCode: ExitErrorCode
}
export type ExitFail = IExitError
/** /**
* uni.exit成功回调函数定义 * uni.exit成功回调函数定义
*/ */
...@@ -12,7 +27,7 @@ export type ExitSuccessCallback = (res: ExitSuccess) => void ...@@ -12,7 +27,7 @@ export type ExitSuccessCallback = (res: ExitSuccess) => void
/** /**
* uni.exit失败回调函数定义 * uni.exit失败回调函数定义
*/ */
export type ExitFailCallback = (res: UniError) => void export type ExitFailCallback = (res: ExitFail) => void
/** /**
* uni.exit完成回调函数定义 * uni.exit完成回调函数定义
*/ */
......
import { ExitErrorCode, IExitError } from "./interface.uts"
/** /**
* 错误主题 * 错误主题
*/ */
...@@ -18,3 +20,17 @@ export const UniErrors:Map<number, string> = new Map([ ...@@ -18,3 +20,17 @@ export const UniErrors:Map<number, string> = new Map([
*/ */
[12002, 'unknown error'] [12002, 'unknown error']
]); ]);
/**
* ExitFail的实现
*/
export class ExitFailImpl extends UniError implements IExitError {
constructor (
errCode: ExitErrorCode
) {
super()
this.errSubject = UniErrorSubject
this.errCode = errCode
this.errMsg = UniErrors[errCode] ?? "";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册