mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:31:13 -05:00
Enable RLS on rate limits table
This commit is contained in:
63
src/lib/errorHandler.ts
Normal file
63
src/lib/errorHandler.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { toast } from 'sonner';
|
||||
import { logger } from './logger';
|
||||
|
||||
export type ErrorContext = {
|
||||
action: string;
|
||||
userId?: string;
|
||||
metadata?: Record<string, any>;
|
||||
};
|
||||
|
||||
export class AppError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public code: string,
|
||||
public userMessage?: string
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'AppError';
|
||||
}
|
||||
}
|
||||
|
||||
export const handleError = (
|
||||
error: unknown,
|
||||
context: ErrorContext
|
||||
): void => {
|
||||
const errorMessage = error instanceof AppError
|
||||
? error.userMessage || error.message
|
||||
: error instanceof Error
|
||||
? error.message
|
||||
: 'An unexpected error occurred';
|
||||
|
||||
// Log to console/monitoring
|
||||
logger.error('Error occurred', {
|
||||
...context,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined
|
||||
});
|
||||
|
||||
// Show user-friendly toast
|
||||
toast.error(context.action, {
|
||||
description: errorMessage,
|
||||
duration: 5000
|
||||
});
|
||||
};
|
||||
|
||||
export const handleSuccess = (
|
||||
title: string,
|
||||
description?: string
|
||||
): void => {
|
||||
toast.success(title, {
|
||||
description,
|
||||
duration: 3000
|
||||
});
|
||||
};
|
||||
|
||||
export const handleInfo = (
|
||||
title: string,
|
||||
description?: string
|
||||
): void => {
|
||||
toast.info(title, {
|
||||
description,
|
||||
duration: 4000
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user