
Extensive Responses without Exceptions
Reported by Matt Todd | June 26th, 2008 @ 08:58 AM | in Release 0.5.1
Currently, the easiest way to respond with anything other than a 200 OK response or a 404 Not Found response is to throw an exception. This is trivial, but it of course causes problems with flow control and isn't exactly the best API.
A better option would to provide some sort of lookup method similar to ok but including a symbolic version of the HTTP errors as well. (This will require some additional information included with the exceptions.rb file, but that is a trivial change.)
Here is an example:
class Foos < Application
  def create
    @foo = Foo.new
    # pre-save logic here
    if @foo.save
      status :created
    else
      error :unprocessable_entity
    end
  end
end
Of course, other method names may be better, but these were the first two I came up with. Technically, error and status could be aliases.
Comments and changes to this ticket
- 
         Matt Todd June 26th, 2008 @ 11:16 AM- State changed from new to resolved
- Tag set to api, http, response, status
 (from [b8fbb9e40eb1aef1d230b36f3d4d070a2bec5ab0]) Added a simple way to respond without raising exceptions explicitly. [#44 state:resolved] 
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
 Create new ticket
 Create new ticket
 Matt Todd
      Matt Todd