default exception doesn't render with correct content type

I just noticed something I think is interesting and wanted to see what
everyone felt about it. Using a quick and dirty scaffold to create a
resource, I found that if I hit a show url, with an invalid id, it
will throw an exception in html instead of xml.

Here is how you repeat this.

$ rails testing_rest
$ cd testing_rest
$ ./script/generate scaffold person name:string
$ rake db:migrate
$ ./script/server

From another window

$ curl -i -H "Accept: application/xml" -H "Content-Type: application/
xml" http://127.0.0.1:3000/people

So far, so good. I was returned an empty array in xml

HTTP/1.1 200 OK
...
Content-Type: application/xml; charset=utf-8
...

<?xml version="1.0" encoding="UTF-8"?>
<nil-classes type="array"/>

dusty wrote:

require 'my_exception_handler'
ActionController::Base.send :include, MyExceptionHandler
ActionController::Base.consider_all_requests_local = false

something like the following will also work..

class Application < ActionController::Base
  around_filter :catch_exceptions

  def catch_exceptions
    begin
      yield
    rescue Exception => e
      render :xml => e.message, :status => 500
    end
  end

end

Thanks for the reply. That would be much easier. The filters are
nice, unfortunately, it doesn't catch things like
ActionController::RoutingErrors. At least its not for me. It does
catch things like notfound errors within an action though.

dusty wrote:

Thanks for the reply. That would be much easier. The filters are
nice, unfortunately, it doesn't catch things like
ActionController::RoutingErrors. At least its not for me. It does
catch things like notfound errors within an action though.

You are right, it won't catch routing errors as they are thrown before
the surround_filters get a chance to party :frowning:

ilan