PlatformErrorHandler
An Angular ErrorHandler implementation that captures unhandled exceptions and forwards them to the Cairn bug-report API.
Import
import { PlatformErrorHandler } from '@mpratyush54/sdk-angular';
Registered automatically by PlatformModule.forRoot() — you typically do not use this class directly.
How It Works
- Angular calls
handleError(error)when an unhandled exception occurs. - Extracts
error.messageanderror.stackand redacts credential-like values. - POSTs to
POST /api/sdk/bug-report(Authorization: Bearer <token>, sent viaHttpBackend) with:projectId,environmentdescription—error.messagecategory: 'angular-error'consoleLogs— single entry with levelerror, the message, and stack tracebrowserInfo—userAgentand current URLappState— empty object
- Falls back to
console.error('[Platform] Unhandled error:', error).
Registration
import { PlatformModule } from '@mpratyush54/sdk-angular';
@NgModule({
imports: [
PlatformModule.forRoot({
apiBase: 'https://platform.example.com',
token: 'sdk_live_xxxx',
projectId: 'my-app',
}),
],
})
export class AppModule {}
Error Handling
- The bug-report POST is wrapped in a try/catch — a failure to report never causes a secondary error.
- The original error is still logged to the console after reporting.
- Only errors that Angular routes to the
ErrorHandlerare captured (unhandled promises, zone errors, etc.).