Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 1x 1x 14x 1x 1x 17x 17x 17x 17x 17x 10x 10x 10x 10x 10x 10x 10x 10x 17x 17x 17x 17x 4x 4x 4x 4x 4x 4x 4x 4x 17x 17x | 'use client';
interface ClientErrorReport {
message: string;
stack?: string;
url: string;
userAgent: string;
timestamp: string;
componentStack?: string;
metadata?: Record<string, unknown>;
}
// Report error to API
async function reportError(error: ClientErrorReport): Promise<void> {
try {
await fetch('/api/monitoring/errors', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(error)});
} catch (e) {
console.error('Failed to report error:', e);
}
}
// Initialize client-side error capturing
export function initClientErrorCapture(): void {
if (typeof window === 'undefined') return;
// Capture unhandled errors
window.onerror = (message, source, lineno, colno, error) => {
reportError({
message: String(message),
stack: error?.stack,
url: window.location.href,
userAgent: navigator.userAgent,
timestamp: new Date().toISOString(),
metadata: { source, lineno, colno }});
return false; // Let default handler run too
};
// Capture unhandled promise rejections
window.onunhandledrejection = (event) => {
const error = event.reason;
reportError({
message: error?.message || 'Unhandled Promise Rejection',
stack: error?.stack,
url: window.location.href,
userAgent: navigator.userAgent,
timestamp: new Date().toISOString(),
metadata: { type: 'unhandledrejection' }});
};
}
|