mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #1344 from sharelatex/bg-handle-filestore-errors
handle non-sucess responses from filestore copy GitOrigin-RevId: f00766066a5a2cf20116aa9c8d876f78fae8953f
This commit is contained in:
parent
da6711dc99
commit
724e2e8fcd
3 changed files with 32 additions and 5 deletions
|
@ -99,10 +99,17 @@ module.exports = FileStoreHandler =
|
||||||
file_id:oldFile_id
|
file_id:oldFile_id
|
||||||
uri: @_buildUrl(newProject_id, newFile_id)
|
uri: @_buildUrl(newProject_id, newFile_id)
|
||||||
timeout:fiveMinsInMs
|
timeout:fiveMinsInMs
|
||||||
request opts, (err)->
|
request opts, (err, response)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, oldProject_id:oldProject_id, oldFile_id:oldFile_id, newProject_id:newProject_id, newFile_id:newFile_id, "something went wrong telling filestore api to copy file"
|
logger.err err:err, oldProject_id:oldProject_id, oldFile_id:oldFile_id, newProject_id:newProject_id, newFile_id:newFile_id, "something went wrong telling filestore api to copy file"
|
||||||
callback(err, opts.uri)
|
callback(err)
|
||||||
|
else if 200 <= response.statusCode < 300
|
||||||
|
# successful response
|
||||||
|
callback(null, opts.uri)
|
||||||
|
else
|
||||||
|
err = new Error("non-ok response from filestore for copyFile: #{response.statusCode}")
|
||||||
|
logger.err {uri: opts.uri, statusCode: response.statusCode}, "error uploading to filestore"
|
||||||
|
callback(err)
|
||||||
|
|
||||||
_buildUrl: (project_id, file_id)->
|
_buildUrl: (project_id, file_id)->
|
||||||
return "#{settings.apis.filestore.url}/project/#{project_id}/file/#{file_id}"
|
return "#{settings.apis.filestore.url}/project/#{project_id}/file/#{file_id}"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
express = require("express")
|
express = require("express")
|
||||||
|
bodyParser = require "body-parser"
|
||||||
app = express()
|
app = express()
|
||||||
|
|
||||||
module.exports = MockFileStoreApi =
|
module.exports = MockFileStoreApi =
|
||||||
|
@ -22,6 +23,18 @@ module.exports = MockFileStoreApi =
|
||||||
{ content } = @files[project_id][file_id]
|
{ content } = @files[project_id][file_id]
|
||||||
res.send content
|
res.send content
|
||||||
|
|
||||||
|
# handle file copying
|
||||||
|
app.put "/project/:project_id/file/:file_id", bodyParser.json(), (req, res, next) =>
|
||||||
|
{project_id, file_id} = req.params
|
||||||
|
source = req.body.source
|
||||||
|
{content} = @files[source.project_id]?[source.file_id]
|
||||||
|
if !content?
|
||||||
|
res.sendStatus 500
|
||||||
|
else
|
||||||
|
@files[project_id] ?= {}
|
||||||
|
@files[project_id][file_id] = { content }
|
||||||
|
res.sendStatus 200
|
||||||
|
|
||||||
app.listen 3009, (error) ->
|
app.listen 3009, (error) ->
|
||||||
throw error if error?
|
throw error if error?
|
||||||
.on "error", (error) ->
|
.on "error", (error) ->
|
||||||
|
|
|
@ -210,7 +210,7 @@ describe "FileStoreHandler", ->
|
||||||
@newFile_id = "new file id"
|
@newFile_id = "new file id"
|
||||||
|
|
||||||
it "should post json", (done)->
|
it "should post json", (done)->
|
||||||
@request.callsArgWith(1, null)
|
@request.callsArgWith(1, null, {statusCode: 200})
|
||||||
|
|
||||||
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, =>
|
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, =>
|
||||||
@request.args[0][0].method.should.equal "put"
|
@request.args[0][0].method.should.equal "put"
|
||||||
|
@ -220,13 +220,13 @@ describe "FileStoreHandler", ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "builds the correct url", (done)->
|
it "builds the correct url", (done)->
|
||||||
@request.callsArgWith(1, null)
|
@request.callsArgWith(1, null, {statusCode: 200})
|
||||||
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, =>
|
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, =>
|
||||||
@handler._buildUrl.calledWith(@newProject_id, @newFile_id).should.equal true
|
@handler._buildUrl.calledWith(@newProject_id, @newFile_id).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "returns the url", (done)->
|
it "returns the url", (done)->
|
||||||
@request.callsArgWith(1, null)
|
@request.callsArgWith(1, null, {statusCode: 200})
|
||||||
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, (err, url) =>
|
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, (err, url) =>
|
||||||
url.should.equal "http://filestore.stubbedBuilder.com"
|
url.should.equal "http://filestore.stubbedBuilder.com"
|
||||||
done()
|
done()
|
||||||
|
@ -237,3 +237,10 @@ describe "FileStoreHandler", ->
|
||||||
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, (err)=>
|
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, (err)=>
|
||||||
err.should.equal error
|
err.should.equal error
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should return an error for a non-success statusCode", (done)->
|
||||||
|
@request.callsArgWith(1, null, {statusCode: 500})
|
||||||
|
@handler.copyFile @project_id, @file_id, @newProject_id, @newFile_id, (err)=>
|
||||||
|
err.should.be.an('error')
|
||||||
|
err.message.should.equal 'non-ok response from filestore for copyFile: 500'
|
||||||
|
done()
|
Loading…
Reference in a new issue