Просмотр исходного кода

error if doc lines are not array when unarchiving

Henry Oswald 9 лет назад
Родитель
Сommit
dbfe5ac712

+ 3 - 0
services/docstore/app/coffee/DocArchiveManager.coffee

@@ -67,6 +67,9 @@ module.exports = DocArchive =
 			if err? || res.statusCode != 200
 				logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "something went wrong unarchiving doc from aws"
 				return callback new Errors.NotFoundError("Error in S3 request")
+			if !(lines instanceof Array)
+				logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "doc lines from aws are not in array format, likely not JSON parsable"
+				return callback(new Error("Error unpacking doc"))
 			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), {lines}, (err) ->
 				return callback(err) if err?
 				logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3"

+ 8 - 0
services/docstore/test/unit/coffee/DocArchiveManager.coffee → services/docstore/test/unit/coffee/DocArchiveManagerTests.coffee

@@ -124,6 +124,14 @@ describe "DocArchiveManager", ->
 				should.exist err
 				done()
 
+		it "should error if the doc lines are a string not an array", (done)->
+			@request.get = sinon.stub().callsArgWith(1, null, statusCode:200, "this is a string")
+			@request.del = sinon.stub()
+			@DocArchiveManager.unarchiveDoc @project_id, @mongoDocs[0], (err)=>
+				should.exist err
+				@request.del.called.should.equal false
+				done()
+
 	describe "archiveAllDocs", ->
 
 		it "should archive all project docs which are not in s3", (done)->