From ccc53ef50da29e87b14c9045e8598a4fd1bc771a Mon Sep 17 00:00:00 2001 From: yanyilin Date: Thu, 2 Nov 2023 18:39:59 +0800 Subject: [PATCH] =?UTF-8?q?uni-exit=E4=BC=98=E5=8C=96UniError=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-exit/utssdk/app-ios/index.uts | 4 ++-- uni_modules/uni-exit/utssdk/interface.uts | 17 ++++++++++++++++- uni_modules/uni-exit/utssdk/unierror.uts | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/uni_modules/uni-exit/utssdk/app-ios/index.uts b/uni_modules/uni-exit/utssdk/app-ios/index.uts index 77a5905..3241c67 100644 --- a/uni_modules/uni-exit/utssdk/app-ios/index.uts +++ b/uni_modules/uni-exit/utssdk/app-ios/index.uts @@ -1,5 +1,5 @@ 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" * iOS平台不支持,触发错误回调 */ 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?.complete?.(err) } diff --git a/uni_modules/uni-exit/utssdk/interface.uts b/uni_modules/uni-exit/utssdk/interface.uts index 0df1394..923b4ff 100644 --- a/uni_modules/uni-exit/utssdk/interface.uts +++ b/uni_modules/uni-exit/utssdk/interface.uts @@ -5,6 +5,21 @@ export type ExitSuccess = { errMsg: string } +/** + * 错误码 + * - 12001: 系统不支持 + * - 12002: 未知错误 + */ +export type ExitErrorCode = 12001 | 12002 + +/** + * uni.exit失败回调参数 + */ +export interface IExitError extends IUniError { + errCode: ExitErrorCode +} +export type ExitFail = IExitError + /** * uni.exit成功回调函数定义 */ @@ -12,7 +27,7 @@ export type ExitSuccessCallback = (res: ExitSuccess) => void /** * uni.exit失败回调函数定义 */ -export type ExitFailCallback = (res: UniError) => void +export type ExitFailCallback = (res: ExitFail) => void /** * uni.exit完成回调函数定义 */ diff --git a/uni_modules/uni-exit/utssdk/unierror.uts b/uni_modules/uni-exit/utssdk/unierror.uts index 68bbd48..93518b7 100644 --- a/uni_modules/uni-exit/utssdk/unierror.uts +++ b/uni_modules/uni-exit/utssdk/unierror.uts @@ -1,3 +1,5 @@ +import { ExitErrorCode, IExitError } from "./interface.uts" + /** * 错误主题 */ @@ -18,3 +20,17 @@ export const UniErrors:Map = new Map([ */ [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] ?? ""; + } +} -- GitLab