Commits

Kenneth Jørgensen committed ee02276

Renamed proxyErrors to catch on EventMessage

  • Participants
  • Parent commits 059c54d

Comments (0)

Files changed (3)

 * *Feature:* Implemented `replyError()` on `EventMessage` to allow for easy handling of errors.
 * *Feature:* Implemented `toJSON()`  and `fromJSON()` on `EventMessage`.
 * *Feature:* Implemented `getRequired()`  and `getOptional()` on `EventMessage` for data retrieval.
-* *Feature:* Implemented `proxyErrors()` on `EventMessage` to handle automatic proxying of asynchronous errors. ([pull/2][pull/2])
+* *Feature:* Implemented `catch()` on `EventMessage` to handle automatic catching of asynchronous errors. ([pull/2][pull/2])
 * *Feature:* `getOptional` and `getRequired` on `EventMessage` can now return deep values using JSON dot syntax.
 * *Fix:* `EventMessages` with empty datasets would throw undefined errors with `getRequired` and `getOptional`.
 

spec/core/EventMessageSpec.coffee

 
 		it "should propagate own errors unless it has a reply handler", ->
 			# msg has an error:
-			# msg.proxyErrors (reply) =>
+			# msg.catch (reply) =>
 			# data on `reply` should also be propagated.
 
-			proxyFunc = msg.proxyErrors handler
+			proxyFunc = msg.catch handler
 			msg.status = "error"
 			msg.error = "Error"
 			msgNoReply.status = "error"
 			msgNoReply.error = "Error"
 			# No reply should throw the exception directly.
-			testNoReply = -> msgNoReply.proxyErrors handler
+			testNoReply = -> msgNoReply.catch handler
 			expect(testNoReply).toThrow "Error"
 			expect(handler.callCount).toBe 0
 			# With reply handler should pass the error along.
-			msg.proxyErrors handler
+			msg.catch handler
 			waitsFor (-> replier.called), "Replier never called", 100
 			runs ->
 				expect(replier.callCount).toBe 1
 
 		it "should propagate reply errors unless it has a reply handler", ->
 			# reply has an error:
-			# msg.proxyErrors (reply) =>
+			# msg.catch (reply) =>
 			# data on `reply` should also be propagated.
 
 			# No reply should throw the exception directly.
-			proxyFuncNoReply = msgNoReply.proxyErrors handler
+			proxyFuncNoReply = msgNoReply.catch handler
 			testNoReply = -> proxyFuncNoReply errorMsg
 			expect(testNoReply).toThrow "Error"
 			expect(handler.callCount).toBe 0
 			# With reply handler should pass the error along.
-			proxyFunc = msg.proxyErrors handler
+			proxyFunc = msg.catch handler
 			proxyFunc errorMsg
 			waitsFor (-> replier.called), "Replier never called", 100
 			runs ->
 
 		it "should propagate thrown errors unless it has a reply handler", ->
 			# Supplied handler threw an error:
-			# msg.proxy (reply) =>
+			# msg.catch (reply) =>
 			handler = sinon.spy -> throw new Error "Error"
 			# No reply should throw the exception directly.
-			proxyFuncNoReply = msgNoReply.proxyErrors handler
+			proxyFuncNoReply = msgNoReply.catch handler
 			testNoReply = -> proxyFuncNoReply new EventMessage
 			expect(testNoReply).toThrow "Error"
 			expect(handler.callCount).toBe 1
 			# With reply handler should pass the error along.
-			proxyFunc = msg.proxyErrors handler
+			proxyFunc = msg.catch handler
 			proxyFunc new EventMessage
 			waitsFor (-> replier.called), "Replier never called", 100
 			runs ->
 
 		it "should accept an optional message an proxy error unless it has a reply handler", ->
 			# otherMsg has an error:
-			# msg.proxy otherMsg, (reply) =>
+			# msg.catch otherMsg, (reply) =>
 
 			# No reply should throw the exception directly.
-			testNoReply = -> msgNoReply.proxyErrors errorMsg, handler
+			testNoReply = -> msgNoReply.catch errorMsg, handler
 			expect(testNoReply).toThrow "Error"
 			expect(handler.callCount).toBe 0
 			# With reply handler should pass the error along.
-			msg.proxyErrors errorMsg, handler
+			msg.catch errorMsg, handler
 			waitsFor (-> replier.called), "Replier never called", 100
 			runs ->
 				expect(replier.callCount).toBe 1

src/core/EventMessage.coffee

 	# removing the need to constantly check incoming messages for errors.
 	# Example usage:
 	#
-	#     @send "address", msg.proxyErrors otherMsg, (reply) ->
+	#     @send "address", msg.catch otherMsg, (reply) ->
 	#
 	# In the above example, proxyErrors will check msg and otherMsg for errors, and pass them to the reply handler
 	# for msg. If no errors are detected, it will execute the supplied handler inside a try/catch block, and pass
 	# any errors back through msg.
 	# If no reply handler exists on msg, errors will be rethrown, or no try/catch block will be used.
 	# otherMsg is optional.
-	proxyErrors: (otherMsg, handler) ->
+	catch: (otherMsg, handler) ->
 		unless otherMsg instanceof EventMessage and _.isFunction handler
 			if _.isFunction otherMsg
 				handler = otherMsg