Răsfoiți Sursa

Check for case where the source file is not found

Shane Kilkelly 8 ani în urmă
părinte
comite
ee1b32eee1

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

@@ -32,6 +32,14 @@ BadDataError = (message) ->
 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 =
 
 	sanitizeData: (data) ->
@@ -58,7 +66,11 @@ module.exports = ProjectFileAgent =
 						project_id: source_project_id,
 						path: source_entity_path
 					}, (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
 
 	_writeEntityToDisk: (project_id, entity_id, type, callback=(err, location)->) ->
@@ -80,7 +92,9 @@ module.exports = ProjectFileAgent =
 		else if error instanceof BadDataError
 			res.status(400).send("The submitted data is not valid")
 		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
 			next(error)
 		next()

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

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