Преглед изворни кода

Check for case where the source file is not found

Shane Kilkelly пре 8 година
родитељ
комит
ee1b32eee1

+ 16 - 2
services/web/app/coffee/Features/LinkedFiles/ProjectFileAgent.coffee

@@ -32,6 +32,14 @@ BadDataError = (message) ->
 BadDataError.prototype.__proto__ = Error.prototype
 BadDataError.prototype.__proto__ = Error.prototype
 
 
 
 
+FileNotFoundError = (message) ->
+	error = new Error(message)
+	error.name = 'BadData'
+	error.__proto__ = FileNotFoundError.prototype
+	return error
+FileNotFoundError.prototype.__proto__ = Error.prototype
+
+
 module.exports = ProjectFileAgent =
 module.exports = ProjectFileAgent =
 
 
 	sanitizeData: (data) ->
 	sanitizeData: (data) ->
@@ -58,7 +66,11 @@ module.exports = ProjectFileAgent =
 						project_id: source_project_id,
 						project_id: source_project_id,
 						path: source_entity_path
 						path: source_entity_path
 					}, (err, entity, type) ->
 					}, (err, entity, type) ->
-						return callback(err) if err?  # also applies when file not found
+						# return callback(err) if err?  # also applies when file not found
+						if err?
+							if err.toString().match(/^not found.*/)
+								err = new FileNotFoundError()
+							return callback(err)
 						ProjectFileAgent._writeEntityToDisk source_project_id, entity._id, type, callback
 						ProjectFileAgent._writeEntityToDisk source_project_id, entity._id, type, callback
 
 
 	_writeEntityToDisk: (project_id, entity_id, type, callback=(err, location)->) ->
 	_writeEntityToDisk: (project_id, entity_id, type, callback=(err, location)->) ->
@@ -80,7 +92,9 @@ module.exports = ProjectFileAgent =
 		else if error instanceof BadDataError
 		else if error instanceof BadDataError
 			res.status(400).send("The submitted data is not valid")
 			res.status(400).send("The submitted data is not valid")
 		else if error instanceof BadEntityTypeError
 		else if error instanceof BadEntityTypeError
-			res.status(404).send("The file is the wrong type")
+			res.status(400).send("The file is the wrong type")
+		else if error instanceof FileNotFoundError
+			res.status(404).send("File not found")
 		else
 		else
 			next(error)
 			next(error)
 		next()
 		next()

+ 1 - 1
services/web/app/coffee/Features/LinkedFiles/UrlAgent.coffee

@@ -65,4 +65,4 @@ module.exports = UrlAgent = {
 		if !Settings.apis?.linkedUrlProxy?.url?
 		if !Settings.apis?.linkedUrlProxy?.url?
 			throw new Error('no linked url proxy configured')
 			throw new Error('no linked url proxy configured')
 		return "#{Settings.apis.linkedUrlProxy.url}?url=#{encodeURIComponent(url)}"
 		return "#{Settings.apis.linkedUrlProxy.url}?url=#{encodeURIComponent(url)}"
-}
+}