Explorar o código

handling error

Henrique Dias %!s(int64=11) %!d(string=hai) anos
pai
achega
5ba14522da

+ 2 - 2
services/docstore/app/coffee/DocArchiveManager.coffee

@@ -27,7 +27,7 @@ module.exports = DocArchive =
 		request.put options, (err, res)->
 		request.put options, (err, res)->
 			if err? || res.statusCode != 200
 			if err? || res.statusCode != 200
 				logger.err err:err, res:res, "something went wrong archiving doc in aws"
 				logger.err err:err, res:res, "something went wrong archiving doc in aws"
-				return callback(err)
+				return callback new Errors.NotFoundError("Error in S3 request")
 			MongoManager.markDocAsArchived doc._id, doc.rev, (error) ->
 			MongoManager.markDocAsArchived doc._id, doc.rev, (error) ->
 				return callback(error) if error?
 				return callback(error) if error?
 				callback()
 				callback()
@@ -52,7 +52,7 @@ module.exports = DocArchive =
 		request.get options, (err, res, lines)->
 		request.get options, (err, res, lines)->
 			if err? || res.statusCode != 200
 			if err? || res.statusCode != 200
 				logger.err err:err, res:res, "something went wrong unarchiving doc from aws"
 				logger.err err:err, res:res, "something went wrong unarchiving doc from aws"
-				return callback(err)
+				return callback new Errors.NotFoundError("Error in S3 request")
 			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), lines, (error) ->
 			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), lines, (error) ->
 				return callback(error) if error?
 				return callback(error) if error?
 				callback()
 				callback()

+ 1 - 1
services/docstore/config/settings.defaults.coffee

@@ -17,4 +17,4 @@ module.exports =
 	#	s3:
 	#	s3:
 	#		key: ""
 	#		key: ""
 	#		secret: ""
 	#		secret: ""
-	
+	#	fail: false

+ 51 - 39
services/docstore/test/acceptance/coffee/ArchiveDocsTests.coffee

@@ -37,46 +37,58 @@ if Settings.filestore?.backend == "s3"
 		afterEach (done) ->
 		afterEach (done) ->
 			db.docs.remove({project_id: @project_id}, done)
 			db.docs.remove({project_id: @project_id}, done)
 
 
-		describe "Archiving all docs", ->
-			beforeEach (done) ->
+		if !Settings.filestore?.fail
 
 
-				DocstoreClient.archiveAllDoc @project_id, (error, @res) =>
-					done()
+			describe "Archiving all docs", ->
+				beforeEach (done) ->
 
 
-			it "should archive all the docs", (done) ->
-				@res.statusCode.should.equal 204
-				done()
-
-			it "should set inS3 and unset lines in each doc", (done) ->
-
-				jobs = for archiveDoc in @docs
-					do (archiveDoc) =>
-						(callback) => 
-							db.docs.findOne _id: archiveDoc._id, (error, doc) =>
-								should.not.exist doc.lines
-								doc.inS3.should.equal true
-								callback()
-				async.series jobs, done
-
-			it "should be able get the same docs back", (done) ->
-
-				jobs = for archiveDoc in @docs
-					do (archiveDoc) =>
-						(callback) => 
-							DocstoreClient.getS3Doc @project_id, archiveDoc._id, (error, res, doc) =>
-								doc.toString().should.equal archiveDoc.lines.toString()
-								callback()
-				async.series jobs, done
-
-
-		describe "Unarchiving all docs", ->
-
-			it "should unarchive all the docs", (done) ->
-				DocstoreClient.archiveAllDoc @project_id, (error, res) =>
-					DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
-						throw error if error?
-						docs.length.should.equal @docs.length
-						for doc, i in docs
-							doc.lines.should.deep.equal @docs[i].lines
+					DocstoreClient.archiveAllDoc @project_id, (error, @res) =>
 						done()
 						done()
 
 
+				it "should archive all the docs", (done) ->
+					@res.statusCode.should.equal 204
+					done()
+
+				it "should set inS3 and unset lines in each doc", (done) ->
+
+					jobs = for archiveDoc in @docs
+						do (archiveDoc) =>
+							(callback) => 
+								db.docs.findOne _id: archiveDoc._id, (error, doc) =>
+									should.not.exist doc.lines
+									doc.inS3.should.equal true
+									callback()
+					async.series jobs, done
+
+				it "should be able get the same docs back", (done) ->
+
+					jobs = for archiveDoc in @docs
+						do (archiveDoc) =>
+							(callback) => 
+								DocstoreClient.getS3Doc @project_id, archiveDoc._id, (error, res, doc) =>
+									doc.toString().should.equal archiveDoc.lines.toString()
+									callback()
+					async.series jobs, done
+
+
+			describe "Unarchiving all docs", ->
+
+				it "should unarchive all the docs", (done) ->
+					DocstoreClient.archiveAllDoc @project_id, (error, res) =>
+						DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
+							throw error if error?
+							docs.length.should.equal @docs.length
+							for doc, i in docs
+								doc.lines.should.deep.equal @docs[i].lines
+							done()
+
+		# set fail to true and also run the docstore service with a denied config
+		if Settings.filestore?.fail
+
+			describe "Test S3 fail request", ->
+
+				it "should return a 404", (done) ->
+
+					DocstoreClient.archiveAllDoc @project_id, (error, res) =>
+						res.statusCode.should.equal 404
+						done()