Просмотр исходного кода

Use errors from ProjectFileAgent

Shane Kilkelly 8 лет назад
Родитель
Сommit
708e809df6

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

@@ -58,9 +58,12 @@ SourceFileNotFoundError = (message) ->
 SourceFileNotFoundError.prototype.__proto__ = Error.prototype
 SourceFileNotFoundError.prototype.__proto__ = Error.prototype
 
 
 
 
-module.exports = ProjectFileAgent =
+module.exports = ProjectFileAgent = {
 
 
-	V1ProjectNotFoundError: V1ProjectNotFoundError
+	V1ProjectNotFoundError
+	BadDataError
+	ProjectNotFoundError
+	V1ProjectNotFoundError
 
 
 	_v1ProjectNotFoundMessage: "Sorry, the source project is not yet imported to Overleaf v2. Please import it to Overleaf v2 to refresh this file"
 	_v1ProjectNotFoundMessage: "Sorry, the source project is not yet imported to Overleaf v2. Please import it to Overleaf v2 to refresh this file"
 
 
@@ -163,3 +166,4 @@ module.exports = ProjectFileAgent =
 		else
 		else
 			next(error)
 			next(error)
 		next()
 		next()
+}

+ 2 - 18
services/web/app/coffee/Features/LinkedFiles/ProjectOutputFileAgent.coffee

@@ -11,22 +11,6 @@ _ = require "underscore"
 request = require "request"
 request = require "request"
 
 
 
 
-BadDataError = (message) ->
-	error = new Error(message)
-	error.name = 'BadData'
-	error.__proto__ = BadDataError.prototype
-	return error
-BadDataError.prototype.__proto__ = Error.prototype
-
-
-ProjectNotFoundError = (message) ->
-	error = new Error(message)
-	error.name = 'ProjectNotFound'
-	error.__proto__ = ProjectNotFoundError.prototype
-	return error
-ProjectNotFoundError.prototype.__proto__ = Error.prototype
-
-
 OutputFileFetchFailedError = (message) ->
 OutputFileFetchFailedError = (message) ->
 	error = new Error(message)
 	error = new Error(message)
 	error.name = 'OutputFileFetchFailedError'
 	error.name = 'OutputFileFetchFailedError'
@@ -92,11 +76,11 @@ module.exports = ProjectOutputFileAgent = {
 							callback(error)
 							callback(error)
 
 
 	handleError: (error, req, res, next) ->
 	handleError: (error, req, res, next) ->
-		if error instanceof BadDataError
+		if error instanceof ProjectFileAgent.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 OutputFileFetchFailedError
 		else if error instanceof OutputFileFetchFailedError
 			res.status(404).send("Could not get output file")
 			res.status(404).send("Could not get output file")
-		else if error instanceof ProjectNotFoundError
+		else if error instanceof ProjectFileAgent.ProjectNotFoundError
 			res.status(404).send("Project not found")
 			res.status(404).send("Project not found")
 		else if error instanceof ProjectFileAgent.V1ProjectNotFoundError
 		else if error instanceof ProjectFileAgent.V1ProjectNotFoundError
 			res.status(409).send(ProjectFileAgent._v1ProjectNotFoundMessage)
 			res.status(409).send(ProjectFileAgent._v1ProjectNotFoundMessage)