docs(changeset): feat(error-manager): implement centralized error reporting system
This commit is contained in:
166
src/ErrorBoundary/ErrorManager.README.md
Normal file
166
src/ErrorBoundary/ErrorManager.README.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# ErrorManager
|
||||
|
||||
Centralized error reporting for ErrorBoundary components.
|
||||
|
||||
## Setup
|
||||
|
||||
### Sentry Integration
|
||||
|
||||
```typescript
|
||||
import { errorManager } from './ErrorBoundary';
|
||||
|
||||
errorManager.configure({
|
||||
enabled: true,
|
||||
sentry: {
|
||||
dsn: 'https://your-sentry-dsn@sentry.io/project-id',
|
||||
environment: 'production',
|
||||
release: '1.0.0',
|
||||
sampleRate: 1.0,
|
||||
ignoreErrors: ['ResizeObserver loop limit exceeded'],
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Custom API Integration
|
||||
|
||||
```typescript
|
||||
errorManager.configure({
|
||||
enabled: true,
|
||||
customAPI: {
|
||||
endpoint: 'https://api.yourapp.com/errors',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer token',
|
||||
},
|
||||
transformPayload: (report) => ({
|
||||
message: report.error.message,
|
||||
stack: report.error.stack,
|
||||
level: report.severity,
|
||||
timestamp: report.timestamp,
|
||||
}),
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Custom Reporter
|
||||
|
||||
```typescript
|
||||
errorManager.configure({
|
||||
enabled: true,
|
||||
reporters: [
|
||||
{
|
||||
name: 'CustomLogger',
|
||||
isEnabled: () => true,
|
||||
captureError: async (report) => {
|
||||
console.error('Error:', report.error);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
### Multiple Reporters
|
||||
|
||||
```typescript
|
||||
errorManager.configure({
|
||||
enabled: true,
|
||||
sentry: { dsn: 'your-dsn' },
|
||||
customAPI: { endpoint: 'your-endpoint' },
|
||||
reporters: [customReporter],
|
||||
});
|
||||
```
|
||||
|
||||
## Hooks
|
||||
|
||||
### beforeReport
|
||||
|
||||
```typescript
|
||||
errorManager.configure({
|
||||
beforeReport: (report) => {
|
||||
// Filter errors
|
||||
if (report.error.message.includes('ResizeObserver')) {
|
||||
return null; // Skip reporting
|
||||
}
|
||||
|
||||
// Enrich with user data
|
||||
report.context = {
|
||||
...report.context,
|
||||
user: { id: getCurrentUserId() },
|
||||
tags: { feature: 'checkout' },
|
||||
};
|
||||
|
||||
return report;
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### onReportSuccess / onReportFailure
|
||||
|
||||
```typescript
|
||||
errorManager.configure({
|
||||
onReportSuccess: (report) => {
|
||||
console.log('Error reported successfully');
|
||||
},
|
||||
onReportFailure: (error, report) => {
|
||||
console.error('Failed to report error:', error);
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Manual Reporting
|
||||
|
||||
```typescript
|
||||
try {
|
||||
riskyOperation();
|
||||
} catch (error) {
|
||||
await errorManager.reportError(error as Error, null, {
|
||||
namespace: 'checkout',
|
||||
tags: { step: 'payment' },
|
||||
extra: { orderId: '123' },
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Disable/Enable
|
||||
|
||||
```typescript
|
||||
// Disable reporting
|
||||
errorManager.configure({ enabled: false });
|
||||
|
||||
// Enable reporting
|
||||
errorManager.configure({ enabled: true });
|
||||
```
|
||||
|
||||
## ErrorBoundary Integration
|
||||
|
||||
Automatic - errors caught by `ReactErrorBoundary` or `ReactBasicErrorBoundary` are automatically reported.
|
||||
|
||||
Manual report button in `ReactErrorBoundary` UI also sends to ErrorManager.
|
||||
|
||||
## Install Sentry (optional)
|
||||
|
||||
```bash
|
||||
npm install @sentry/react
|
||||
```
|
||||
|
||||
## Types
|
||||
|
||||
```typescript
|
||||
type ErrorSeverity = 'fatal' | 'error' | 'warning' | 'info' | 'debug';
|
||||
|
||||
interface ErrorContext {
|
||||
namespace?: string;
|
||||
componentStack?: string;
|
||||
user?: Record<string, any>;
|
||||
tags?: Record<string, string>;
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
interface ErrorReport {
|
||||
error: Error;
|
||||
errorInfo?: any;
|
||||
severity?: ErrorSeverity;
|
||||
context?: ErrorContext;
|
||||
timestamp?: number;
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user