• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit AbilityKit
19 */
20
21import { AsyncCallback } from './@ohos.base';
22import * as _ErrorObserver from './application/ErrorObserver';
23import { LoopObserver as _LoopObserver } from './application/LoopObserver';
24
25/**
26 * This module provides the function of error manager.
27 *
28 * @namespace errorManager
29 * @syscap SystemCapability.Ability.AbilityRuntime.Core
30 * @since 9
31 */
32/**
33 * This module provides the function of error manager.
34 *
35 * @namespace errorManager
36 * @syscap SystemCapability.Ability.AbilityRuntime.Core
37 * @atomicservice
38 * @since 11
39 */
40declare namespace errorManager {
41  /**
42   * Register error observer.
43   *
44   * @param { 'error' } type - error.
45   * @param { ErrorObserver } observer - The error observer.
46   * @returns { number } Returns the number code of the observer.
47   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
48   * 2. Incorrect parameter types; 3. Parameter verification failed.
49   * @throws { BusinessError } 16000003 - Id does not exist.
50   * @syscap SystemCapability.Ability.AbilityRuntime.Core
51   * @since 9
52   */
53  /**
54   * Register error observer.
55   *
56   * @param { 'error' } type - error.
57   * @param { ErrorObserver } observer - The error observer.
58   * @returns { number } Returns the number code of the observer.
59   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
60   * 2. Incorrect parameter types; 3. Parameter verification failed.
61   * @throws { BusinessError } 16000003 - Id does not exist.
62   * @syscap SystemCapability.Ability.AbilityRuntime.Core
63   * @atomicservice
64   * @since 11
65   */
66  function on(type: 'error', observer: ErrorObserver): number;
67
68  /**
69   * Unregister error observer.
70   *
71   * @param { 'error' } type - error.
72   * @param { number } observerId - Indicates the number code of the observer.
73   * @param { AsyncCallback<void> } callback - The callback of off.
74   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
75   * 2. Incorrect parameter types; 3. Parameter verification failed.
76   * @throws { BusinessError } 16000003 - Id does not exist.
77   * @syscap SystemCapability.Ability.AbilityRuntime.Core
78   * @since 9
79   */
80  /**
81   * Unregister error observer.
82   *
83   * @param { 'error' } type - error.
84   * @param { number } observerId - Indicates the number code of the observer.
85   * @param { AsyncCallback<void> } callback - The callback of off.
86   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
87   * 2. Incorrect parameter types; 3. Parameter verification failed.
88   * @throws { BusinessError } 16000003 - Id does not exist.
89   * @syscap SystemCapability.Ability.AbilityRuntime.Core
90   * @atomicservice
91   * @since 11
92   */
93  function off(type: 'error', observerId: number, callback: AsyncCallback<void>): void;
94
95  /**
96   * Unregister error observer.
97   *
98   * @param { 'error' } type - error.
99   * @param { number } observerId - Indicates the number code of the observer.
100   * @returns { Promise<void> } The promise returned by the function.
101   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
102   * 2. Incorrect parameter types; 3. Parameter verification failed.
103   * @throws { BusinessError } 16000003 - Id does not exist.
104   * @syscap SystemCapability.Ability.AbilityRuntime.Core
105   * @since 9
106   */
107  /**
108   * Unregister error observer.
109   *
110   * @param { 'error' } type - error.
111   * @param { number } observerId - Indicates the number code of the observer.
112   * @returns { Promise<void> } The promise returned by the function.
113   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
114   * 2. Incorrect parameter types; 3. Parameter verification failed.
115   * @throws { BusinessError } 16000003 - Id does not exist.
116   * @syscap SystemCapability.Ability.AbilityRuntime.Core
117   * @atomicservice
118   * @since 11
119   */
120  function off(type: 'error', observerId: number): Promise<void>;
121
122  /**
123   * Register loop observer. This function can only by called from main thread,
124   * and if call this function multiple times, the last
125   * modification will overwrite the previous one.
126   *
127   * @param { 'loopObserver' } type - loopObserver.
128   * @param { number } timeout - Indicates timeout(ms) value of loop observer.
129   * @param { LoopObserver } observer - The loop observer.
130   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
131   * 2. Incorrect parameter types; 3. Parameter verification failed.
132   * @syscap SystemCapability.Ability.AbilityRuntime.Core
133   * @atomicservice
134   * @since 12
135   */
136  function on(type: 'loopObserver', timeout: number, observer: LoopObserver): void;
137
138  /**
139   * Unregister loop observer. This function can only by called from main thread.
140   *
141   * @param { 'loopObserver' } type - loopObserver.
142   * @param { LoopObserver } observer - The loop observer.
143   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
144   * 2. Incorrect parameter types; 3. Parameter verification failed.
145   * @syscap SystemCapability.Ability.AbilityRuntime.Core
146   * @atomicservice
147   * @since 12
148   */
149  function off(type: 'loopObserver', observer?: LoopObserver): void;
150
151  /**
152   * Register unhandled rejection observer.
153   *
154   * @param { 'unhandledRejection' } type - 'unhandledRejection'.
155   * @param { UnhandledRejectionObserver } observer - The unhandled rejection observer.
156   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
157   * 2. Incorrect parameter types; 3. Parameter verification failed.
158   * @throws { BusinessError } 16200001 - If the caller is invalid.
159   * @syscap SystemCapability.Ability.AbilityRuntime.Core
160   * @atomicservice
161   * @since 12
162   */
163  function on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void;
164
165  /**
166   * Unregister unhandled rejection observer.
167   *
168   * @param { 'unhandledRejection' } type - error.
169   * @param { UnhandledRejectionObserver } [observer]  - the registered observer
170   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
171   * 2. Incorrect parameter types; 3. Parameter verification failed.
172   * @throws { BusinessError } 16200001 - If the caller is invalid.
173   * @throws { BusinessError } 16300004 - If the observer does not exist
174   * @syscap SystemCapability.Ability.AbilityRuntime.Core
175   * @atomicservice
176   * @since 12
177   */
178  function off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void;
179
180  /**
181   * The observer will be called by system when an error occurs.
182   *
183   * @syscap SystemCapability.Ability.AbilityRuntime.Core
184   * @since 9
185   */
186  /**
187   * The observer will be called by system when an error occurs.
188   *
189   * @syscap SystemCapability.Ability.AbilityRuntime.Core
190   * @atomicservice
191   * @since 11
192   */
193  export type ErrorObserver = _ErrorObserver.default;
194  /**
195   * The observer will be called when application main thread execute timeout.
196   *
197   * @syscap SystemCapability.Ability.AbilityRuntime.Core
198   * @atomicservice
199   * @since 12
200   */
201  export type LoopObserver = _LoopObserver;
202  /**
203   * The observer will be called by system when an unhandled rejection occurs.
204   *
205   * { Error | any } reason - the reason of the rejection, typically of Error type
206   * { Promise<any> } promise - the promise that is rejected
207   * @syscap SystemCapability.Ability.AbilityRuntime.Core
208   * @atomicservice
209   * @since 12
210   */
211  export type UnhandledRejectionObserver = (reason: Error | any, promise: Promise<any>) => void;
212}
213
214export default errorManager;
215