mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 14:43:46 -05:00
Return more informative errors
This commit is contained in:
parent
3213c562bc
commit
5cd66aad58
5 changed files with 50 additions and 13 deletions
|
@ -13,12 +13,13 @@ ProjectPersistenceManager = require "./app/js/ProjectPersistenceManager"
|
||||||
require("./app/js/db").sync()
|
require("./app/js/db").sync()
|
||||||
|
|
||||||
express = require "express"
|
express = require "express"
|
||||||
|
bodyParser = require "body-parser"
|
||||||
app = express()
|
app = express()
|
||||||
|
|
||||||
app.use Metrics.http.monitor(logger)
|
app.use Metrics.http.monitor(logger)
|
||||||
|
|
||||||
app.post "/project/:project_id/compile", express.bodyParser(), CompileController.compile
|
app.post "/project/:project_id/compile", bodyParser.json(limit: "2mb"), CompileController.compile
|
||||||
app.del "/project/:project_id", CompileController.clearCache
|
app.delete "/project/:project_id", CompileController.clearCache
|
||||||
|
|
||||||
app.get "/project/:project_id/sync/code", CompileController.syncFromCode
|
app.get "/project/:project_id/sync/code", CompileController.syncFromCode
|
||||||
app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf
|
app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf
|
||||||
|
|
|
@ -16,8 +16,11 @@ module.exports = CompileController =
|
||||||
CompileManager.doCompile request, (error, outputFiles = []) ->
|
CompileManager.doCompile request, (error, outputFiles = []) ->
|
||||||
if error?
|
if error?
|
||||||
logger.error err: error, project_id: request.project_id, "error running compile"
|
logger.error err: error, project_id: request.project_id, "error running compile"
|
||||||
error = error.message or error
|
if error.timedout
|
||||||
status = "failure"
|
status = "timedout"
|
||||||
|
else
|
||||||
|
status = "error"
|
||||||
|
code = 500
|
||||||
else
|
else
|
||||||
status = "failure"
|
status = "failure"
|
||||||
for file in outputFiles
|
for file in outputFiles
|
||||||
|
@ -25,10 +28,10 @@ module.exports = CompileController =
|
||||||
status = "success"
|
status = "success"
|
||||||
|
|
||||||
timer.done()
|
timer.done()
|
||||||
res.send JSON.stringify {
|
res.send (code or 200), {
|
||||||
compile:
|
compile:
|
||||||
status: status
|
status: status
|
||||||
error: error
|
error: error?.message or error
|
||||||
outputFiles: outputFiles.map (file) ->
|
outputFiles: outputFiles.map (file) ->
|
||||||
url: "#{Settings.apis.clsi.url}/project/#{request.project_id}/output/#{file.path}"
|
url: "#{Settings.apis.clsi.url}/project/#{request.project_id}/output/#{file.path}"
|
||||||
type: file.type
|
type: file.type
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
"author": "James Allen <james@sharelatex.com>",
|
"author": "James Allen <james@sharelatex.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "0.2.9",
|
"async": "0.2.9",
|
||||||
"express": "3.3.1",
|
|
||||||
"lynx": "0.0.11",
|
"lynx": "0.0.11",
|
||||||
"mkdirp": "0.3.5",
|
"mkdirp": "0.3.5",
|
||||||
"mysql": "2.0.0-alpha7",
|
"mysql": "2.0.0-alpha7",
|
||||||
|
@ -16,7 +15,9 @@
|
||||||
"sequelize": "~2.0.0-beta.2",
|
"sequelize": "~2.0.0-beta.2",
|
||||||
"wrench": "~1.5.4",
|
"wrench": "~1.5.4",
|
||||||
"smoke-test-sharelatex": "git+https://github.com/sharelatex/smoke-test-sharelatex.git#master",
|
"smoke-test-sharelatex": "git+https://github.com/sharelatex/smoke-test-sharelatex.git#master",
|
||||||
"sqlite3": "~2.2.0"
|
"sqlite3": "~2.2.0",
|
||||||
|
"express": "^4.2.0",
|
||||||
|
"body-parser": "^1.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "1.10.0",
|
"mocha": "1.10.0",
|
||||||
|
|
|
@ -22,6 +22,6 @@ describe "Timed out compile", ->
|
||||||
it "should return a timeout error", ->
|
it "should return a timeout error", ->
|
||||||
@body.compile.error.should.equal "container timed out"
|
@body.compile.error.should.equal "container timed out"
|
||||||
|
|
||||||
it "should return a failure status", ->
|
it "should return a timedout status", ->
|
||||||
@body.compile.status.should.equal "failure"
|
@body.compile.status.should.equal "timedout"
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe "CompileController", ->
|
||||||
|
|
||||||
it "should return the JSON response", ->
|
it "should return the JSON response", ->
|
||||||
@res.send
|
@res.send
|
||||||
.calledWith(JSON.stringify
|
.calledWith(200,
|
||||||
compile:
|
compile:
|
||||||
status: "success"
|
status: "success"
|
||||||
error: null
|
error: null
|
||||||
|
@ -83,14 +83,46 @@ describe "CompileController", ->
|
||||||
|
|
||||||
it "should return the JSON response with the error", ->
|
it "should return the JSON response with the error", ->
|
||||||
@res.send
|
@res.send
|
||||||
.calledWith(JSON.stringify
|
.calledWith(500,
|
||||||
compile:
|
compile:
|
||||||
status: "failure"
|
status: "error"
|
||||||
error: @message
|
error: @message
|
||||||
outputFiles: []
|
outputFiles: []
|
||||||
)
|
)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when the request times out", ->
|
||||||
|
beforeEach ->
|
||||||
|
@error = new Error(@message = "container timed out")
|
||||||
|
@error.timedout = true
|
||||||
|
@CompileManager.doCompile = sinon.stub().callsArgWith(1, @error, null)
|
||||||
|
@CompileController.compile @req, @res
|
||||||
|
|
||||||
|
it "should return the JSON response with the timeout status", ->
|
||||||
|
@res.send
|
||||||
|
.calledWith(200,
|
||||||
|
compile:
|
||||||
|
status: "timedout"
|
||||||
|
error: @message
|
||||||
|
outputFiles: []
|
||||||
|
)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when the request returns no output files", ->
|
||||||
|
beforeEach ->
|
||||||
|
@CompileManager.doCompile = sinon.stub().callsArgWith(1, null, [])
|
||||||
|
@CompileController.compile @req, @res
|
||||||
|
|
||||||
|
it "should return the JSON response with the failure status", ->
|
||||||
|
@res.send
|
||||||
|
.calledWith(200,
|
||||||
|
compile:
|
||||||
|
error: null
|
||||||
|
status: "failure"
|
||||||
|
outputFiles: []
|
||||||
|
)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "syncFromCode", ->
|
describe "syncFromCode", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@file = "main.tex"
|
@file = "main.tex"
|
||||||
|
|
Loading…
Reference in a new issue