From 3b31ba4b1e6a1b74daefd8dc6c7c244256e55747 Mon Sep 17 00:00:00 2001 From: nathanusask Date: Tue, 27 Feb 2024 22:52:05 +0800 Subject: [PATCH] feat: add UnhandledRejectionObserver Signed-off-by: yangxuguang3@huawei.com refactor: per PR feedback Signed-off-by: yangxuguang-huawei refactor Signed-off-by: yangxuguang-huawei --- api/@ohos.app.ability.errorManager.d.ts | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/api/@ohos.app.ability.errorManager.d.ts b/api/@ohos.app.ability.errorManager.d.ts index 2514510295..d2be9731fb 100644 --- a/api/@ohos.app.ability.errorManager.d.ts +++ b/api/@ohos.app.ability.errorManager.d.ts @@ -140,6 +140,33 @@ declare namespace errorManager { */ function off(type: 'loopObserver', observer?: LoopObserver): void; + /** + * Register unhandled rejection observer. + * + * @param { 'unhandledRejection' } type - 'unhandledRejection'. + * @param { UnhandledRejectionObserver } observer - The unhandled rejection observer. + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @throws { BusinessError } 16200001 - If the caller is invalid. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + function on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void; + + /** + * Unregister unhandled rejection observer. + * + * @param { 'unhandledRejection' } type - error. + * @param { UnhandledRejectionObserver } [observer] - the registered observer + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @throws { BusinessError } 16200001 - If the caller is invalid. + * @throws { BusinessError } 16300004 - If the observer does not exist + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + function off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void; + /** * The observer will be called by system when an error occurs. * @@ -162,6 +189,16 @@ declare namespace errorManager { * @since 12 */ export type LoopObserver = _LoopObserver.default; + /** + * The observer will be called by system when an unhandled rejection occurs. + * + * { Error | any } reason - the reason of the rejection, typically of Error type + * { Promise } promise - the promise that is rejected + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @atomicservice + * @since 12 + */ + export type UnhandledRejectionObserver = (reason: Error | any, promise: Promise) => void; } export default errorManager; -- Gitee