Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Extensive Responses without Exceptions

#44

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.

Reported by Matt Todd · June 26th, 2008 @ 08:58 AM

State: resolved
Milestone: Release 0.5.1
Assigned to: Matt Todd Matt Todd

Activity

  1. Matt Todd
    Matt Todd
    • 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]

    http://github.com/mtodd/halcyon/...

    June 26th, 2008 @ 11:16 AM

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.