Skip to content

Commit 8acca32

Browse files
committed
Refactor exception handler
1 parent d333a78 commit 8acca32

File tree

25 files changed

+126
-43
lines changed

25 files changed

+126
-43
lines changed

@types/core/compile/attributes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Attributes {
1818
);
1919
$rootScope: import("../scope/scope.js").Scope;
2020
$animate: import("../../interface.ts").AnimateService;
21-
$exceptionHandler: import("../../interface.ts").ErrorHandler;
21+
$exceptionHandler: import("../../interface.ts").ExceptionHandler;
2222
$sce: any;
2323
$attr: {};
2424
/** @type {import("../../shared/noderef.js").NodeRef} */

@types/directive/model/model.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class NgModelController {
141141
$$element: Element;
142142
$$animate: import("../../interface.ts").AnimateService;
143143
$$parse: import("../../core/parse/interface.ts").ParseService;
144-
$$exceptionHandler: import("../../interface.ts").ErrorHandler;
144+
$$exceptionHandler: import("../../interface.ts").ExceptionHandler;
145145
$$hasNativeValidators: boolean;
146146
$$classCache: {};
147147
$$eventRemovers: Set<any>;

@types/interface.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./core/di/internal-injector.js";
1212
export * from "./core/scope/scope.js";
1313
export * from "./services/cookie/cookie.js";
1414
export * from "./services/cookie/interface.ts";
15+
export * from "./services/exception/exception.ts";
1516
export * from "./services/exception/interface.ts";
1617
export * from "./core/parse/interface.ts";
1718
import { Attributes } from "./core/compile/attributes.js";

@types/namespace.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
AnchorScrollService as TAnchorScrollService,
1414
} from "./services/anchor-scroll/anchor-scroll.js";
1515
import { ControllerService as TControllerService } from "./core/controller/interface.ts";
16-
import { ErrorHandler as TErrorHandler } from "./services/exception/interface.ts";
16+
import { ExceptionHandler as TExceptionHandler } from "./services/exception/interface.ts";
1717
import { ParseService as TParseService } from "./core/parse/interface.ts";
1818
import { TemplateRequestService as TTemplateRequestService } from "./services/template-request/interface.ts";
1919
import { HttpParamSerializer as THttpParamSerializer } from "./services/http/interface.ts";
@@ -115,7 +115,7 @@ declare global {
115115
type CompileService = TCompileFn;
116116
type ControllerService = TControllerService;
117117
type CookieService = TCookieService;
118-
type ExceptionHandlerService = TErrorHandler;
118+
type ExceptionHandlerService = TExceptionHandler;
119119
type FilterService = TFilterFactory;
120120
type HttpParamSerializerSerService = THttpParamSerializer;
121121
type HttpService = THttpService;

@types/services/cookie/cookie.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class CookieService {
2828
);
2929
/** @type {ng.CookieOptions} */
3030
defaults: ng.CookieOptions;
31-
$exceptionHandler: import("../exception/interface.ts").ErrorHandler;
31+
$exceptionHandler: import("../exception/interface.ts").ExceptionHandler;
3232
/**
3333
* Retrieves a raw cookie value.
3434
*

@types/services/exception/exception-handler.d.ts renamed to @types/services/exception/exception.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This service receives uncaught exceptions from both synchronous and asynchronous operations.
55
* Its purpose is to provide a central point through which the framework
6-
* surfaces errors.
6+
* processes errors.
77
*
88
* By default, `$exceptionHandler` simply rethrows the exception. This ensures fail-fast
99
* behavior, making errors visible immediately in development and in unit tests.
@@ -37,7 +37,7 @@
3737
* }
3838
* ```
3939
*
40-
* @see {@link angular.ErrorHandler AngularTS ErrorHandler}
40+
* @see {@link ng.ExceptionHandlerService ExceptionHandlerService}
4141
*/
4242
/**
4343
* Provider for the `$exceptionHandler` service.
@@ -48,7 +48,7 @@
4848
*/
4949
export class ExceptionHandlerProvider {
5050
/** @type {ng.ExceptionHandlerService} */
51-
errorHandler: ng.ExceptionHandlerService;
51+
handler: ng.ExceptionHandlerService;
5252
/**
5353
* @returns {ng.ExceptionHandlerService}
5454
*/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* A callback type for handling errors.
33
*
4-
* @param exception - The exception associated with the error.
4+
* @param {Error} exception - The exception associated with the error.
55
*/
6-
export type ErrorHandler = (exception: Error) => void;
6+
export type ExceptionHandler = (exception: Error) => void;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: $exceptionHandlerProvider
3+
description: >
4+
Configuration provider for `$exceptionHandler` service.
5+
---
6+
7+
### Description
8+
9+
Instance of [ng.ExceptionHandlerProvider](../../../typedoc/classes/ExceptionHandlerProvider.html) for
10+
configuring the `$exceptionHandler` service.
11+
12+
The default implementation returns
13+
[ng.ExceptionHandler](../../../typedoc/types/ExceptionHandler.html) function, which simply rethrows the exception.
14+
15+
**NOTE**: custom implementations should always rethrow the error as the framework assumes that `$exceptionHandler` always does the throwing.
16+
17+
18+
### Properties
19+
20+
---
21+
22+
#### $exceptionHandler.handler
23+
24+
Customize the `exceptionHandler` function.
25+
26+
- **Type:** [ng.ExceptionHandler](../../../typedoc/classes/PubSub.html)
27+
- **Default:** Function that rethrows the exception.
28+
- **Example:**
29+
```js
30+
angular.module('demo', [])
31+
.config([
32+
"$exceptionHandlerProvider",
33+
/** @param {ng.ExceptionHandlerProvider} $exceptionHandlerProvider */
34+
($exceptionHandlerProvider) => {
35+
exceptionHandlerProvider.handler = (error) => {
36+
myLogger.capture(error);
37+
// Rethrow to preserve fail-fast behavior:
38+
throw error;
39+
};
40+
}
41+
]);
42+
```
43+
44+
---
45+
46+
For service description, see [$exceptionHandler](../../../docs/service/exceptionhandler/).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: $exceptionHandler
3+
description: >
4+
Error handling service
5+
---
6+
7+
### Description
8+
9+
`$exceptionHandler` is the central hook for uncaught exceptions inside an AngularTS application.
10+
The framework routes all errors from synchronous code, async tasks, expression evaluation, and dependency injection through this service.
11+
12+
By default, it rethrows exceptions that occur during AngularTS-managed execution. This fail-fast behavior ensures errors are visible immediately in development and in unit tests.
13+
<div class="alert alert-danger" role="alert">
14+
15+
**IMPORTANT**: In AngularJS, `$exceptionHandler` only caught errors in expressions and
16+
logged them to the console, using a type signature of `$exceptionHandler(exception, [cause])`.
17+
18+
AngularTS treats `$exceptionHandler` as a single error sink, fails eagerly, and assumes that the [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object or one of its subclasses provides all the context necessary for the client.
19+
20+
</div>
21+
22+
For type description, see [ng.ExceptionHandler](../../../typedoc/types/ExceptionHandler.html).
23+
24+
For service customisation, see [ng.ExceptionHandlerProvider](../../../docs/provider/exceptionhandlerprovider/)

docs/static/typedoc/assets/navigation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)