mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 05:18:21 +00:00
When upload to filestore fails, produce an error
This commit is contained in:
parent
e24873a945
commit
ec25ee9045
2 changed files with 40 additions and 4 deletions
|
@ -25,10 +25,19 @@ module.exports = FileStoreHandler =
|
|||
timeout:fiveMinsInMs
|
||||
writeStream = request(opts)
|
||||
readStream.pipe writeStream
|
||||
writeStream.on "end", callback
|
||||
|
||||
writeStream.on 'response', (response) ->
|
||||
if response.statusCode not in [200, 201]
|
||||
err = new Error("non-ok response from filestore for upload: #{response.statusCode}")
|
||||
logger.err {err, statusCode: response.statusCode}, "error uploading to filestore"
|
||||
callback(err)
|
||||
else
|
||||
callback(null)
|
||||
|
||||
readStream.on "error", (err)->
|
||||
logger.err err:err, project_id:project_id, file_id:file_id, fsPath:fsPath, "something went wrong on the read stream of uploadFileFromDisk"
|
||||
callback err
|
||||
|
||||
writeStream.on "error", (err)->
|
||||
logger.err err:err, project_id:project_id, file_id:file_id, fsPath:fsPath, "something went wrong on the write stream of uploadFileFromDisk"
|
||||
callback err
|
||||
|
@ -79,4 +88,4 @@ module.exports = FileStoreHandler =
|
|||
callback(err)
|
||||
|
||||
_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}"
|
||||
|
|
|
@ -17,8 +17,8 @@ describe "FileStoreHandler", ->
|
|||
@writeStream =
|
||||
my:"writeStream"
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
if type == "response"
|
||||
cb({statusCode: 200})
|
||||
@readStream = {my:"readStream", on: sinon.stub()}
|
||||
@request = sinon.stub()
|
||||
@settings = apis:{filestore:{url:"http//filestore.sharelatex.test"}}
|
||||
|
@ -79,6 +79,16 @@ describe "FileStoreHandler", ->
|
|||
@handler._buildUrl.calledWith(@project_id, @file_id).should.equal true
|
||||
done()
|
||||
|
||||
it 'should callback with null', (done) ->
|
||||
@fs.createReadStream.returns
|
||||
pipe:->
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, (err) =>
|
||||
expect(err).to.not.exist
|
||||
done()
|
||||
|
||||
describe "symlink", ->
|
||||
it "should not read file if it is symlink", (done)->
|
||||
@isSafeOnFileSystem = false
|
||||
|
@ -86,6 +96,23 @@ describe "FileStoreHandler", ->
|
|||
@fs.createReadStream.called.should.equal false
|
||||
done()
|
||||
|
||||
describe "when upload fails", ->
|
||||
beforeEach ->
|
||||
@writeStream.on = (type, cb) ->
|
||||
if type == "response"
|
||||
cb({statusCode: 500})
|
||||
|
||||
it 'should callback with an error', (done) ->
|
||||
@fs.createReadStream.returns
|
||||
pipe:->
|
||||
on: (type, cb)->
|
||||
if type == "end"
|
||||
cb()
|
||||
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, (err) =>
|
||||
expect(err).to.exist
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
describe "deleteFile", ->
|
||||
|
||||
it "should send a delete request to filestore api", (done)->
|
||||
|
|
Loading…
Reference in a new issue