feat(ui): handle errors on folder creation or folder/file renaming
- protect file_management_service::rename_file with validate_storage_name - remove specific rename modal and use the generic modal class (less duplicate) - handle errors on modal action: do not close the modal on error and display this error - hide "Go to parent folder" contextMenu if section is files and folder is the same as current one
This commit is contained in:
@@ -685,6 +685,10 @@ const fileOps = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new folder
|
||||
* @param {string} name - Folder name
|
||||
*/
|
||||
/**
|
||||
* Create a new folder
|
||||
* @param {string} name - Folder name
|
||||
@@ -718,13 +722,20 @@ const fileOps = {
|
||||
|
||||
ui.showNotification('Folder created', `"${name}" created successfully`);
|
||||
} else {
|
||||
const errorData = await response.text();
|
||||
console.error('Create folder error:', errorData);
|
||||
ui.showNotification('Error', 'Error creating the folder');
|
||||
const errorText = await response.text();
|
||||
console.error('Create folder error:', errorText);
|
||||
let errorMessage = 'Unknown error';
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
errorMessage = errorData.error || response.statusText;
|
||||
} catch (_e) {
|
||||
errorMessage = errorText || response.statusText;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating folder:', error);
|
||||
ui.showNotification('Error', 'Error creating the folder');
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -978,6 +989,12 @@ const fileOps = {
|
||||
* @param {string} newName - New file name
|
||||
* @returns {Promise<boolean>} - Success status
|
||||
*/
|
||||
/**
|
||||
* Rename a file
|
||||
* @param {string} fileId - File ID
|
||||
* @param {string} newName - New file name
|
||||
* @returns {Promise<string|null>} - null on success, error message string on failure
|
||||
*/
|
||||
async renameFile(fileId, newName) {
|
||||
try {
|
||||
console.log(`Renaming file ${fileId} to "${newName}"`);
|
||||
@@ -995,24 +1012,22 @@ const fileOps = {
|
||||
|
||||
if (response.ok) {
|
||||
ui.showNotification(i18n.t('notifications.file_renamed'), i18n.t('notifications.file_renamed_to', { name: newName }));
|
||||
return true;
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
console.error('Error response:', errorText);
|
||||
let errorMessage = 'Unknown error';
|
||||
try {
|
||||
const errorData = JSON.parse(errorText);
|
||||
errorMessage = errorData.error || response.statusText;
|
||||
} catch (_e) {
|
||||
errorMessage = errorText || response.statusText;
|
||||
throw new Error(errorData.error || response.statusText);
|
||||
} catch (parseError) {
|
||||
if (parseError instanceof SyntaxError) {
|
||||
throw new Error(errorText || response.statusText);
|
||||
}
|
||||
throw parseError;
|
||||
}
|
||||
ui.showNotification('Error', `Error renaming the file: ${errorMessage}`);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error renaming file:', error);
|
||||
ui.showNotification('Error', 'Error renaming the file');
|
||||
return false;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1022,6 +1037,12 @@ const fileOps = {
|
||||
* @param {string} newName - New folder name
|
||||
* @returns {Promise<boolean>} - Success status
|
||||
*/
|
||||
/**
|
||||
* Rename a folder
|
||||
* @param {string} folderId - Folder ID
|
||||
* @param {string} newName - New folder name
|
||||
* @returns {Promise<string|null>} - null on success, error message string on failure
|
||||
*/
|
||||
async renameFolder(folderId, newName) {
|
||||
try {
|
||||
console.log(`Renaming folder ${folderId} to "${newName}"`);
|
||||
@@ -1039,28 +1060,23 @@ const fileOps = {
|
||||
|
||||
if (response.ok) {
|
||||
ui.showNotification('Folder renamed', `Folder renamed to "${newName}"`);
|
||||
return true;
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
console.error('Error response:', errorText);
|
||||
|
||||
let errorMessage = 'Unknown error';
|
||||
try {
|
||||
// Try to parse as JSON
|
||||
const errorData = JSON.parse(errorText);
|
||||
errorMessage = errorData.error || response.statusText;
|
||||
} catch (_e) {
|
||||
// If not JSON, use text as is
|
||||
errorMessage = errorText || response.statusText;
|
||||
throw new Error(errorData.error || response.statusText);
|
||||
} catch (parseError) {
|
||||
if (parseError instanceof SyntaxError) {
|
||||
throw new Error(errorText || response.statusText);
|
||||
}
|
||||
throw parseError;
|
||||
}
|
||||
|
||||
ui.showNotification('Error', `Error renaming the folder: ${errorMessage}`);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error renaming folder:', error);
|
||||
ui.showNotification('Error', 'Error renaming the folder');
|
||||
return false;
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user