mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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()
|
||||
|
||||
express = require "express"
|
||||
bodyParser = require "body-parser"
|
||||
app = express()
|
||||
|
||||
app.use Metrics.http.monitor(logger)
|
||||
|
||||
app.post "/project/:project_id/compile", express.bodyParser(), CompileController.compile
|
||||
app.del "/project/:project_id", CompileController.clearCache
|
||||
app.post "/project/:project_id/compile", bodyParser.json(limit: "2mb"), CompileController.compile
|
||||
app.delete "/project/:project_id", CompileController.clearCache
|
||||
|
||||
app.get "/project/:project_id/sync/code", CompileController.syncFromCode
|
||||
app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf
|
||||
|
|
|
@ -16,8 +16,11 @@ module.exports = CompileController =
|
|||
CompileManager.doCompile request, (error, outputFiles = []) ->
|
||||
if error?
|
||||
logger.error err: error, project_id: request.project_id, "error running compile"
|
||||
error = error.message or error
|
||||
status = "failure"
|
||||
if error.timedout
|
||||
status = "timedout"
|
||||
else
|
||||
status = "error"
|
||||
code = 500
|
||||
else
|
||||
status = "failure"
|
||||
for file in outputFiles
|
||||
|
@ -25,10 +28,10 @@ module.exports = CompileController =
|
|||
status = "success"
|
||||
|
||||
timer.done()
|
||||
res.send JSON.stringify {
|
||||
res.send (code or 200), {
|
||||
compile:
|
||||
status: status
|
||||
error: error
|
||||
error: error?.message or error
|
||||
outputFiles: outputFiles.map (file) ->
|
||||
url: "#{Settings.apis.clsi.url}/project/#{request.project_id}/output/#{file.path}"
|
||||
type: file.type
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"author": "James Allen <james@sharelatex.com>",
|
||||
"dependencies": {
|
||||
"async": "0.2.9",
|
||||
"express": "3.3.1",
|
||||
"lynx": "0.0.11",
|
||||
"mkdirp": "0.3.5",
|
||||
"mysql": "2.0.0-alpha7",
|
||||
|
@ -16,7 +15,9 @@
|
|||
"sequelize": "~2.0.0-beta.2",
|
||||
"wrench": "~1.5.4",
|
||||
"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": {
|
||||
"mocha": "1.10.0",
|
||||
|
|
|
@ -22,6 +22,6 @@ describe "Timed out compile", ->
|
|||
it "should return a timeout error", ->
|
||||
@body.compile.error.should.equal "container timed out"
|
||||
|
||||
it "should return a failure status", ->
|
||||
@body.compile.status.should.equal "failure"
|
||||
it "should return a timedout status", ->
|
||||
@body.compile.status.should.equal "timedout"
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ describe "CompileController", ->
|
|||
|
||||
it "should return the JSON response", ->
|
||||
@res.send
|
||||
.calledWith(JSON.stringify
|
||||
.calledWith(200,
|
||||
compile:
|
||||
status: "success"
|
||||
error: null
|
||||
|
@ -83,14 +83,46 @@ describe "CompileController", ->
|
|||
|
||||
it "should return the JSON response with the error", ->
|
||||
@res.send
|
||||
.calledWith(JSON.stringify
|
||||
.calledWith(500,
|
||||
compile:
|
||||
status: "failure"
|
||||
status: "error"
|
||||
error: @message
|
||||
outputFiles: []
|
||||
)
|
||||
.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", ->
|
||||
beforeEach ->
|
||||
@file = "main.tex"
|
||||
|
|
Loading…
Reference in a new issue