You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, if the request email coming in to your application isn't correct in some application-specific way, can't be parsed etc., your callback might look like
if valid?(request)
...
respond( ... )
else
respond usage_response
end
Which is fine for simple cases, but if you have several different error conditions that each call for different behavior/responses, the code starts getting ugly with nested if's. One thing that might be helpful would be a way of exiting the callback early. You could use next -
unless valid_subject?(request)
respond error_invalid_subject
next
end
unless valid_body?(request)
respond error_invalid_body
next
end
... continue processing after validation passes
or to DRY it up, -
validate({:valid_body? => error_invalid_body,
:valid_subject? => error_invalid_subject}) or next
... continue
But somehow that still isn't satisfying. Not suggesting rails-style controller validations, but maybe something Newman::Controller could help with that I'm not thinking of.
The text was updated successfully, but these errors were encountered:
validatedo# check something about the messageendinvalid_requestdo# send a response, log it, etc.end
A failed validation would set some state (or raise an error) which causes invalid_request to be triggered. This could also be done explicitly with some method that could be called from within any matcher. Better names are needed here.
Right now, if the request email coming in to your application isn't correct in some application-specific way, can't be parsed etc., your callback might look like
Which is fine for simple cases, but if you have several different error conditions that each call for different behavior/responses, the code starts getting ugly with nested if's. One thing that might be helpful would be a way of exiting the callback early. You could use
next
-or to DRY it up, -
But somehow that still isn't satisfying. Not suggesting rails-style controller validations, but maybe something
Newman::Controller
could help with that I'm not thinking of.The text was updated successfully, but these errors were encountered: