161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit AbilityKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport { AsyncCallback } from './@ohos.base'; 2261847f8eSopenharmony_ciimport * as _ErrorObserver from './application/ErrorObserver'; 2361847f8eSopenharmony_ciimport { LoopObserver as _LoopObserver } from './application/LoopObserver'; 2461847f8eSopenharmony_ci 2561847f8eSopenharmony_ci/** 2661847f8eSopenharmony_ci * This module provides the function of error manager. 2761847f8eSopenharmony_ci * 2861847f8eSopenharmony_ci * @namespace errorManager 2961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 3061847f8eSopenharmony_ci * @since 9 3161847f8eSopenharmony_ci */ 3261847f8eSopenharmony_ci/** 3361847f8eSopenharmony_ci * This module provides the function of error manager. 3461847f8eSopenharmony_ci * 3561847f8eSopenharmony_ci * @namespace errorManager 3661847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 3761847f8eSopenharmony_ci * @atomicservice 3861847f8eSopenharmony_ci * @since 11 3961847f8eSopenharmony_ci */ 4061847f8eSopenharmony_cideclare namespace errorManager { 4161847f8eSopenharmony_ci /** 4261847f8eSopenharmony_ci * Register error observer. 4361847f8eSopenharmony_ci * 4461847f8eSopenharmony_ci * @param { 'error' } type - error. 4561847f8eSopenharmony_ci * @param { ErrorObserver } observer - The error observer. 4661847f8eSopenharmony_ci * @returns { number } Returns the number code of the observer. 4761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 4861847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 4961847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - Id does not exist. 5061847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 5161847f8eSopenharmony_ci * @since 9 5261847f8eSopenharmony_ci */ 5361847f8eSopenharmony_ci /** 5461847f8eSopenharmony_ci * Register error observer. 5561847f8eSopenharmony_ci * 5661847f8eSopenharmony_ci * @param { 'error' } type - error. 5761847f8eSopenharmony_ci * @param { ErrorObserver } observer - The error observer. 5861847f8eSopenharmony_ci * @returns { number } Returns the number code of the observer. 5961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 6061847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 6161847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - The specified ID does not exist. 6261847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 6361847f8eSopenharmony_ci * @atomicservice 6461847f8eSopenharmony_ci * @since 11 6561847f8eSopenharmony_ci */ 6661847f8eSopenharmony_ci function on(type: 'error', observer: ErrorObserver): number; 6761847f8eSopenharmony_ci 6861847f8eSopenharmony_ci /** 6961847f8eSopenharmony_ci * Unregister error observer. 7061847f8eSopenharmony_ci * 7161847f8eSopenharmony_ci * @param { 'error' } type - error. 7261847f8eSopenharmony_ci * @param { number } observerId - Indicates the number code of the observer. 7361847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback - The callback of off. 7461847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 7561847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 7661847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - Id does not exist. 7761847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 7861847f8eSopenharmony_ci * @since 9 7961847f8eSopenharmony_ci */ 8061847f8eSopenharmony_ci /** 8161847f8eSopenharmony_ci * Unregister error observer. 8261847f8eSopenharmony_ci * 8361847f8eSopenharmony_ci * @param { 'error' } type - error. 8461847f8eSopenharmony_ci * @param { number } observerId - Indicates the number code of the observer. 8561847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback - The callback of off. 8661847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 8761847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 8861847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - The specified ID does not exist. 8961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 9061847f8eSopenharmony_ci * @atomicservice 9161847f8eSopenharmony_ci * @since 11 9261847f8eSopenharmony_ci */ 9361847f8eSopenharmony_ci function off(type: 'error', observerId: number, callback: AsyncCallback<void>): void; 9461847f8eSopenharmony_ci 9561847f8eSopenharmony_ci /** 9661847f8eSopenharmony_ci * Unregister error observer. 9761847f8eSopenharmony_ci * 9861847f8eSopenharmony_ci * @param { 'error' } type - error. 9961847f8eSopenharmony_ci * @param { number } observerId - Indicates the number code of the observer. 10061847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 10161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 10261847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 10361847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - Id does not exist. 10461847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 10561847f8eSopenharmony_ci * @since 9 10661847f8eSopenharmony_ci */ 10761847f8eSopenharmony_ci /** 10861847f8eSopenharmony_ci * Unregister error observer. 10961847f8eSopenharmony_ci * 11061847f8eSopenharmony_ci * @param { 'error' } type - error. 11161847f8eSopenharmony_ci * @param { number } observerId - Indicates the number code of the observer. 11261847f8eSopenharmony_ci * @returns { Promise<void> } The promise returned by the function. 11361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 11461847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 11561847f8eSopenharmony_ci * @throws { BusinessError } 16000003 - The specified ID does not exist. 11661847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 11761847f8eSopenharmony_ci * @atomicservice 11861847f8eSopenharmony_ci * @since 11 11961847f8eSopenharmony_ci */ 12061847f8eSopenharmony_ci function off(type: 'error', observerId: number): Promise<void>; 12161847f8eSopenharmony_ci 12261847f8eSopenharmony_ci /** 12361847f8eSopenharmony_ci * Register loop observer. This function can only by called from main thread, 12461847f8eSopenharmony_ci * and if call this function multiple times, the last 12561847f8eSopenharmony_ci * modification will overwrite the previous one. 12661847f8eSopenharmony_ci * 12761847f8eSopenharmony_ci * @param { 'loopObserver' } type - loopObserver. 12861847f8eSopenharmony_ci * @param { number } timeout - Indicates timeout(ms) value of loop observer. 12961847f8eSopenharmony_ci * @param { LoopObserver } observer - The loop observer. 13061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 13161847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 13261847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 13361847f8eSopenharmony_ci * @atomicservice 13461847f8eSopenharmony_ci * @since 12 13561847f8eSopenharmony_ci */ 13661847f8eSopenharmony_ci function on(type: 'loopObserver', timeout: number, observer: LoopObserver): void; 13761847f8eSopenharmony_ci 13861847f8eSopenharmony_ci /** 13961847f8eSopenharmony_ci * Unregister loop observer. This function can only by called from main thread. 14061847f8eSopenharmony_ci * 14161847f8eSopenharmony_ci * @param { 'loopObserver' } type - loopObserver. 14261847f8eSopenharmony_ci * @param { LoopObserver } observer - The loop observer. 14361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 14461847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 14561847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 14661847f8eSopenharmony_ci * @atomicservice 14761847f8eSopenharmony_ci * @since 12 14861847f8eSopenharmony_ci */ 14961847f8eSopenharmony_ci function off(type: 'loopObserver', observer?: LoopObserver): void; 15061847f8eSopenharmony_ci 15161847f8eSopenharmony_ci /** 15261847f8eSopenharmony_ci * Register unhandled rejection observer. 15361847f8eSopenharmony_ci * 15461847f8eSopenharmony_ci * @param { 'unhandledRejection' } type - 'unhandledRejection'. 15561847f8eSopenharmony_ci * @param { UnhandledRejectionObserver } observer - The unhandled rejection observer. 15661847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 15761847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 15861847f8eSopenharmony_ci * @throws { BusinessError } 16200001 - If the caller is invalid. 15961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 16061847f8eSopenharmony_ci * @atomicservice 16161847f8eSopenharmony_ci * @since 12 16261847f8eSopenharmony_ci */ 16361847f8eSopenharmony_ci function on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void; 16461847f8eSopenharmony_ci 16561847f8eSopenharmony_ci /** 16661847f8eSopenharmony_ci * Unregister unhandled rejection observer. 16761847f8eSopenharmony_ci * 16861847f8eSopenharmony_ci * @param { 'unhandledRejection' } type - error. 16961847f8eSopenharmony_ci * @param { UnhandledRejectionObserver } [observer] - the registered observer 17061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 17161847f8eSopenharmony_ci * 2. Incorrect parameter types; 3. Parameter verification failed. 17261847f8eSopenharmony_ci * @throws { BusinessError } 16200001 - If the caller is invalid. 17361847f8eSopenharmony_ci * @throws { BusinessError } 16300004 - If the observer does not exist 17461847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 17561847f8eSopenharmony_ci * @atomicservice 17661847f8eSopenharmony_ci * @since 12 17761847f8eSopenharmony_ci */ 17861847f8eSopenharmony_ci function off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void; 17961847f8eSopenharmony_ci 18061847f8eSopenharmony_ci /** 18161847f8eSopenharmony_ci * The observer will be called by system when an error occurs. 18261847f8eSopenharmony_ci * 18361847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 18461847f8eSopenharmony_ci * @since 9 18561847f8eSopenharmony_ci */ 18661847f8eSopenharmony_ci /** 18761847f8eSopenharmony_ci * The observer will be called by system when an error occurs. 18861847f8eSopenharmony_ci * 18961847f8eSopenharmony_ci * @typedef { _ErrorObserver.default } 19061847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 19161847f8eSopenharmony_ci * @atomicservice 19261847f8eSopenharmony_ci * @since 11 19361847f8eSopenharmony_ci */ 19461847f8eSopenharmony_ci export type ErrorObserver = _ErrorObserver.default; 19561847f8eSopenharmony_ci /** 19661847f8eSopenharmony_ci * The observer will be called when application main thread execute timeout. 19761847f8eSopenharmony_ci * 19861847f8eSopenharmony_ci * @typedef { _LoopObserver } 19961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 20061847f8eSopenharmony_ci * @atomicservice 20161847f8eSopenharmony_ci * @since 12 20261847f8eSopenharmony_ci */ 20361847f8eSopenharmony_ci export type LoopObserver = _LoopObserver; 20461847f8eSopenharmony_ci /** 20561847f8eSopenharmony_ci * The observer will be called by system when an unhandled rejection occurs. 20661847f8eSopenharmony_ci * 20761847f8eSopenharmony_ci * @typedef { function } 20861847f8eSopenharmony_ci * { Error | any } reason - the reason of the rejection, typically of Error type 20961847f8eSopenharmony_ci * { Promise<any> } promise - the promise that is rejected 21061847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core 21161847f8eSopenharmony_ci * @atomicservice 21261847f8eSopenharmony_ci * @since 12 21361847f8eSopenharmony_ci */ 21461847f8eSopenharmony_ci export type UnhandledRejectionObserver = (reason: Error | any, promise: Promise<any>) => void; 21561847f8eSopenharmony_ci} 21661847f8eSopenharmony_ci 21761847f8eSopenharmony_ciexport default errorManager; 218