Skip to content

Commit 22dc2e4

Browse files
committed
docs(readme): add section on global error handler integration
1 parent 863c2f2 commit 22dc2e4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

libs/core/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,25 @@ bootstrapApplication(AppComponent, {
9797
],
9898
})
9999
```
100+
101+
### Global Error Handler Integration
102+
103+
You can integrate the logger with Angular's global `ErrorHandler` to automatically log all uncaught errors in your application using the `withErrorHandler` feature.
104+
105+
#### Usage Example
106+
107+
Use the `withErrorHandler` function to register a custom error handler that logs uncaught errors through the LoggerService.
108+
109+
```ts
110+
import { provideBrowserGlobalErrorListeners } from '@angular/core'
111+
import { LogLevel, provideLogger, withBrowserConsoleTransport, withErrorHandler } from '@shiftcode/ngx-core'
112+
113+
bootstrapApplication(AppComponent, {
114+
providers: [
115+
provideLogger(withBrowserConsoleTransport({ logLevel: LogLevel.DEBUG }), withErrorHandler()),
116+
117+
/** To also capture global uncaught errors from the browser (e.g., script errors, unhandled promise rejections), use provideBrowserGlobalErrorListeners: */
118+
provideBrowserGlobalErrorListeners(),
119+
],
120+
})
121+
```

0 commit comments

Comments
 (0)