mendicant-university/newman — Issue #34: make it easier to handle application error responses
Author: ericgj
Created: 2012-02-26 19:00:30+00:00
State: open
Labels: feature

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.