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:
@@ -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,8 +153,12 @@ app.get "/heapdump", (req, res)->
|
||||
res.send filename
|
||||
|
||||
app.use (error, req, res, next) ->
|
||||
logger.error err: error, "server error"
|
||||
res.sendStatus(error?.statusCode || 500)
|
||||
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) ->
|
||||
logger.info "CLSI starting up, listening on #{host}:#{port}"
|
||||
|
||||
@@ -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()
|
||||
|
||||
10
app/coffee/Errors.coffee
Normal file
10
app/coffee/Errors.coffee
Normal 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
|
||||
Reference in New Issue
Block a user