mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 17:31:13 -05:00
Approve database migration
This commit is contained in:
80
src/lib/errorBreadcrumbs.ts
Normal file
80
src/lib/errorBreadcrumbs.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Error Breadcrumb Tracking
|
||||
* Captures user actions before errors occur for better debugging
|
||||
*/
|
||||
|
||||
export interface Breadcrumb {
|
||||
timestamp: string;
|
||||
category: 'navigation' | 'user_action' | 'api_call' | 'state_change';
|
||||
message: string;
|
||||
level: 'info' | 'warning' | 'error';
|
||||
data?: Record<string, any>;
|
||||
}
|
||||
|
||||
class BreadcrumbManager {
|
||||
private breadcrumbs: Breadcrumb[] = [];
|
||||
private readonly MAX_BREADCRUMBS = 10;
|
||||
|
||||
add(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void {
|
||||
const newBreadcrumb: Breadcrumb = {
|
||||
...breadcrumb,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
|
||||
this.breadcrumbs.push(newBreadcrumb);
|
||||
|
||||
// Keep only last 10 breadcrumbs
|
||||
if (this.breadcrumbs.length > this.MAX_BREADCRUMBS) {
|
||||
this.breadcrumbs.shift();
|
||||
}
|
||||
}
|
||||
|
||||
getAll(): Breadcrumb[] {
|
||||
return [...this.breadcrumbs];
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.breadcrumbs = [];
|
||||
}
|
||||
}
|
||||
|
||||
export const breadcrumbManager = new BreadcrumbManager();
|
||||
|
||||
// Helper functions for common breadcrumb types
|
||||
export const breadcrumb = {
|
||||
navigation: (to: string, from?: string) => {
|
||||
breadcrumbManager.add({
|
||||
category: 'navigation',
|
||||
message: `Navigated to ${to}`,
|
||||
level: 'info',
|
||||
data: { to, from },
|
||||
});
|
||||
},
|
||||
|
||||
userAction: (action: string, component: string, data?: Record<string, any>) => {
|
||||
breadcrumbManager.add({
|
||||
category: 'user_action',
|
||||
message: `User ${action} in ${component}`,
|
||||
level: 'info',
|
||||
data,
|
||||
});
|
||||
},
|
||||
|
||||
apiCall: (endpoint: string, method: string, status?: number) => {
|
||||
breadcrumbManager.add({
|
||||
category: 'api_call',
|
||||
message: `API ${method} ${endpoint}`,
|
||||
level: status && status >= 400 ? 'error' : 'info',
|
||||
data: { endpoint, method, status },
|
||||
});
|
||||
},
|
||||
|
||||
stateChange: (description: string, data?: Record<string, any>) => {
|
||||
breadcrumbManager.add({
|
||||
category: 'state_change',
|
||||
message: description,
|
||||
level: 'info',
|
||||
data,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user