Use errors from ProjectFileAgent

This commit is contained in:
Shane Kilkelly 2018-06-15 11:17:20 +01:00
parent 2ade78783b
commit 708e809df6
2 changed files with 8 additions and 20 deletions

View file

@ -58,9 +58,12 @@ SourceFileNotFoundError = (message) ->
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"
@ -163,3 +166,4 @@ module.exports = ProjectFileAgent =
else
next(error)
next()
}

View file

@ -11,22 +11,6 @@ _ = require "underscore"
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) ->
error = new Error(message)
error.name = 'OutputFileFetchFailedError'
@ -92,11 +76,11 @@ module.exports = ProjectOutputFileAgent = {
callback(error)
handleError: (error, req, res, next) ->
if error instanceof BadDataError
if error instanceof ProjectFileAgent.BadDataError
res.status(400).send("The submitted data is not valid")
else if error instanceof OutputFileFetchFailedError
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")
else if error instanceof ProjectFileAgent.V1ProjectNotFoundError
res.status(409).send(ProjectFileAgent._v1ProjectNotFoundMessage)