Send a 404 if the project files have gone away when running synctex.

This is semantically nicer than the 500 response which used to be
produced in these circumstances.
This commit is contained in:
Shane Kilkelly 2017-06-23 14:46:40 +01:00
parent 65eaf0ad10
commit a55debb79f
3 changed files with 20 additions and 4 deletions

View file

@ -7,6 +7,7 @@ if Settings.sentry?.dsn?
smokeTest = require "smoke-test-sharelatex"
ContentTypeMapper = require "./app/js/ContentTypeMapper"
Errors = require './app/js/Errors'
Path = require "path"
fs = require "fs"
@ -152,7 +153,11 @@ app.get "/heapdump", (req, res)->
res.send filename
app.use (error, req, res, next) ->
logger.error err: error, "server error"
if error instanceof Errors.NotFoundError
logger.warn {err: error, url: req.url}, "not found error"
return res.sendStatus(404)
else
logger.error {err: error, url: req.url}, "server error"
res.sendStatus(error?.statusCode || 500)
app.listen port = (Settings.internal?.clsi?.port or 3013), host = (Settings.internal?.clsi?.host or "localhost"), (error) ->

View file

@ -13,6 +13,7 @@ fs = require("fs")
fse = require "fs-extra"
os = require("os")
async = require "async"
Errors = require './Errors'
commandRunner = Settings.clsi?.commandRunner or "./CommandRunner"
logger.info commandRunner:commandRunner, "selecting command runner for clsi"
@ -206,11 +207,11 @@ module.exports = CompileManager =
synctexFile = Path.join(synctexDir, "output.synctex.gz")
fs.stat synctexDir, (error, stats) ->
if error?.code is 'ENOENT'
return callback(new Error("called synctex with no output directory"))
return callback(new Errors.NotFoundError("called synctex with no output directory"))
return callback(error) if error?
fs.stat synctexFile, (error, stats) ->
if error?.code is 'ENOENT'
return callback(new Error("called synctex with no output file"))
return callback(new Errors.NotFoundError("called synctex with no output file"))
return callback(error) if error?
return callback(new Error("not a file")) if not stats?.isFile()
callback()

View file

@ -0,0 +1,10 @@
NotFoundError = (message) ->
error = new Error(message)
error.name = "NotFoundError"
error.__proto__ = NotFoundError.prototype
return error
NotFoundError.prototype.__proto__ = Error.prototype
module.exports = Errors =
NotFoundError: NotFoundError