Эх сурвалжийг харах

Don't throw error if the function is not invoked with callback.

Instead, log the error and return early.
Shane Kilkelly 9 жил өмнө
parent
commit
31235beee5

+ 2 - 4
libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee

@@ -93,12 +93,10 @@ describe 'timeAsyncMethod', ->
 			@testObject.nextNumber = (n) ->
 				return n+1
 
-		it 'should throw an error', ->
+		it 'should not throw an error', ->
 			@timeAsyncMethod @testObject, 'nextNumber', 'test.nextNumber'
 			badCall = () =>
 				@testObject.nextNumber 2
-			expect(badCall).to.throw(
-				/^.*expected wrapped method 'nextNumber' to be invoked with a callback.*$/
-			)
+			expect(badCall).to.not.throw(Error)
 
 

+ 3 - 3
libraries/metrics/timeAsyncMethod.coffee

@@ -11,10 +11,10 @@ module.exports = (obj, methodName, prefix, logger) ->
 	obj[methodName] = (originalArgs...) ->
 
 		[firstArgs..., callback] = originalArgs
+
 		if !callback? || typeof callback != 'function'
-			throw new Error(
-				"[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback"
-			)
+			logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback"
+			return
 
 		timer = new metrics.Timer(key)