examforge / src /services /firestoreUtils.ts
Benjahmin's picture
feat: Initial project setup for ExamForge
3679583
Raw
History Blame Contribute Delete
1.33 kB
import { auth } from './firebase';
export enum OperationType {
CREATE = 'create',
UPDATE = 'update',
DELETE = 'delete',
LIST = 'list',
GET = 'get',
WRITE = 'write',
}
export interface FirestoreErrorInfo {
error: string;
operationType: OperationType;
path: string | null;
authInfo: {
userId?: string | null;
email?: string | null;
emailVerified?: boolean | null;
isAnonymous?: boolean | null;
tenantId?: string | null;
providerInfo?: {
providerId?: string | null;
email?: string | null;
}[];
}
}
export function handleFirestoreError(error: unknown, operationType: OperationType, path: string | null) {
const errInfo: FirestoreErrorInfo = {
error: error instanceof Error ? error.message : String(error),
authInfo: {
userId: auth.currentUser?.uid,
email: auth.currentUser?.email,
emailVerified: auth.currentUser?.emailVerified,
isAnonymous: auth.currentUser?.isAnonymous,
tenantId: auth.currentUser?.tenantId,
providerInfo: auth.currentUser?.providerData?.map(provider => ({
providerId: provider.providerId,
email: provider.email,
})) || []
},
operationType,
path
}
console.error('Firestore Error: ', JSON.stringify(errInfo, null, 2));
throw new Error(JSON.stringify(errInfo));
}