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

Instead, log the error and return early.
This commit is contained in:
Shane Kilkelly 2017-03-20 16:17:22 +00:00
parent 9846703be5
commit 31235beee5
2 changed files with 5 additions and 7 deletions

View file

@ -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)

View file

@ -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)