mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 14:11:13 -05:00
Fix rollback system
This commit is contained in:
@@ -164,10 +164,16 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
p_reason: reason
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
if (error) {
|
||||
// Check for authorization error (insufficient_privilege)
|
||||
if (error.code === '42501') {
|
||||
throw new Error('Only moderators can restore previous versions');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (isMountedRef.current) {
|
||||
toast.success('Successfully rolled back to previous version');
|
||||
toast.success('Successfully restored to previous version');
|
||||
await fetchVersions();
|
||||
}
|
||||
return data;
|
||||
@@ -175,7 +181,9 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
logger.error('Failed to rollback version', { entityType, entityId, targetVersionId, error: errorMsg });
|
||||
if (isMountedRef.current) {
|
||||
toast.error(errorMsg);
|
||||
toast.error('Failed to restore version', {
|
||||
description: errorMsg
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user