Add error handling in mkdir_p

This commit is contained in:
James Allen 2016-03-23 15:18:10 +00:00
parent ae5467894b
commit 4d0fe3bf5d

View file

@ -242,6 +242,7 @@ module.exports = ProjectEntityHandler =
return folder.length != 0 return folder.length != 0
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project)=> ProjectGetter.getProjectWithOnlyFolders project_id, (err, project)=>
return callback(err) if err?
if path == '/' if path == '/'
logger.log project_id: project._id, "mkdir is only trying to make path of / so sending back root folder" logger.log project_id: project._id, "mkdir is only trying to make path of / so sending back root folder"
return callback(null, [], project.rootFolder[0]) return callback(null, [], project.rootFolder[0])
@ -255,9 +256,11 @@ module.exports = ProjectEntityHandler =
parentFolder_id = parentFolder._id parentFolder_id = parentFolder._id
builtUpPath = "#{builtUpPath}/#{folderName}" builtUpPath = "#{builtUpPath}/#{folderName}"
projectLocator.findElementByPath project, builtUpPath, (err, foundFolder)=> projectLocator.findElementByPath project, builtUpPath, (err, foundFolder)=>
return callback(err) if err?
if !foundFolder? if !foundFolder?
logger.log path:path, project_id:project._id, folderName:folderName, "making folder from mkdirp" logger.log path:path, project_id:project._id, folderName:folderName, "making folder from mkdirp"
@addFolder project_id, parentFolder_id, folderName, (err, newFolder, parentFolder_id)-> @addFolder project_id, parentFolder_id, folderName, (err, newFolder, parentFolder_id)->
return callback(err) if err?
newFolder.parentFolder_id = parentFolder_id newFolder.parentFolder_id = parentFolder_id
previousFolders.push newFolder previousFolders.push newFolder
callback null, previousFolders callback null, previousFolders