Fix composite submission error handling

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 13:09:54 +00:00
parent 540bd1cd7a
commit 876119c079
2 changed files with 91 additions and 12 deletions

View File

@@ -30,23 +30,60 @@ export const handleError = (
const errorId = (context.metadata?.requestId as string) || crypto.randomUUID();
const shortErrorId = errorId.slice(0, 8);
const errorMessage = error instanceof AppError
? error.userMessage || error.message
: error instanceof Error
? error.message
: 'An unexpected error occurred';
// Enhanced error message and stack extraction
let errorMessage: string;
let stack: string | undefined;
let errorName = 'UnknownError';
if (error instanceof Error) {
errorMessage = error instanceof AppError
? error.userMessage || error.message
: error.message;
stack = error.stack;
errorName = error.name;
} else if (error && typeof error === 'object') {
// Handle Supabase errors (plain objects with message/code/details)
const supabaseError = error as {
message?: string;
code?: string;
details?: string;
hint?: string;
};
errorMessage = supabaseError.message || 'An unexpected error occurred';
errorName = 'SupabaseError';
// Create synthetic stack trace for Supabase errors to aid debugging
if (supabaseError.code || supabaseError.details || supabaseError.hint) {
const stackParts = [
`SupabaseError: ${errorMessage}`,
supabaseError.code ? ` Code: ${supabaseError.code}` : null,
supabaseError.details ? ` Details: ${supabaseError.details}` : null,
supabaseError.hint ? ` Hint: ${supabaseError.hint}` : null,
` at ${context.action}`,
` Reference ID: ${errorId}`
].filter(Boolean);
stack = stackParts.join('\n');
}
} else if (typeof error === 'string') {
errorMessage = error;
} else {
errorMessage = 'An unexpected error occurred';
}
// Log to console/monitoring with enhanced debugging
const stack = error instanceof Error ? error.stack : undefined;
logger.error('Error occurred', {
...context,
error: error instanceof Error ? error.message : String(error),
error: errorMessage,
stack,
errorId,
errorName,
errorType: typeof error,
errorConstructor: error?.constructor?.name,
hasStack: !!stack,
isSyntheticStack: !!(error && typeof error === 'object' && !(error instanceof Error) && stack),
});
// Additional debug logging when stack is missing
@@ -72,9 +109,9 @@ export const handleError = (
p_endpoint: context.action,
p_method: 'ERROR',
p_status_code: 500,
p_error_type: error instanceof Error ? error.name : 'UnknownError',
p_error_type: errorName,
p_error_message: errorMessage,
p_error_stack: error instanceof Error ? error.stack : undefined,
p_error_stack: stack,
p_user_agent: navigator.userAgent,
p_breadcrumbs: JSON.stringify(breadcrumbs),
p_timezone: envContext.timezone,