rescue

I am having problems with rescue actions. Currently using 'development'
and it is sending e-mails no problem but it still drives me to the error
page...

My specific error at this point is
ActionController::InvalidAuthenticityToken
and I am using an expired session to generate the errors.

in application.rb I have...

  # this part doesn't seem to work
  def rescue_action_in_public(exception)
    if exception == "ActionController::InvalidAuthenticityToken"
      flash[:notice]="Your session expired"
      redirect_to :controller => 'login', :action => 'login'
    else
      flash[:notice]="The Application Server dumped"
      request.env["HTTP_REFERER"]
      redirect_to :back
    end
  end

# this part works...I get the e-mails
  protected

  # Provides code to create an email generated upon error
  def log_error(exception)
    super(exception)
    begin
      ErrorMailer.deliver_snapshot(
        exception,
        clean_backtrace(exception),
        session.instance_variable_get("@data"),
        params,
        request.env)
    rescue => e
      logger.error(e)
    end
  end

Craig

I am having problems with rescue actions. Currently using 'development'
and it is sending e-mails no problem but it still drives me to the error
page...

My specific error at this point is
ActionController::InvalidAuthenticityToken
and I am using an expired session to generate the errors.

Your if statement is bogus, you're just comparing an exception object
with a string. Try using is_a? to see if the exception object is an
instance of a given exception class. See also rescue_from

Fred

Fred

> I am having problems with rescue actions. Currently using 'development'
> and it is sending e-mails no problem but it still drives me to the error
> page...
>
> My specific error at this point is
> ActionController::InvalidAuthenticityToken
> and I am using an expired session to generate the errors.
>

Your if statement is bogus, you're just comparing an exception object
with a string. Try using is_a? to see if the exception object is an
instance of a given exception class. See also rescue_from

Fred

Fred
> in application.rb I have...
>
> # this part doesn't seem to work
> def rescue_action_in_public(exception)
> if exception == "ActionController::InvalidAuthenticityToken"
> flash[:notice]="Your session expired"
> redirect_to :controller => 'login', :action => 'login'
> else
> flash[:notice]="The Application Server dumped"
> request.env["HTTP_REFERER"]
> redirect_to :back
> end
> end
>
> # this part works...I get the e-mails
> protected
>
> # Provides code to create an email generated upon error
> def log_error(exception)
> super(exception)
> begin
> ErrorMailer.deliver_snapshot(
> exception,
> clean_backtrace(exception),
> session.instance_variable_get("@data"),
> params,
> request.env)
> rescue => e
> logger.error(e)
> end
> end
>
> Craig

# this part works...I get the e-mails
  protected

  # Provides code to create an email generated upon error
  def log_error(exception)
    super(exception)
    begin
      ErrorMailer.deliver_snapshot(
        exception,
        clean_backtrace(exception),
        session.instance_variable_get("@data"),
        params,
        request.env)
    rescue => e
      logger.error(e)
    end
  end

> # this part works...I get the e-mails
> protected
>
> # Provides code to create an email generated upon error
> def log_error(exception)
> super(exception)
> begin
> ErrorMailer.deliver_snapshot(
> exception,
> clean_backtrace(exception),
> session.instance_variable_get("@data"),
> params,
> request.env)
> rescue => e
> logger.error(e)
> end
> end
----
as long as I am at this, I don't seem to get the environment or session
values either (well, I know if the session is deleted, I wouldn't get
any values but when I have an error in a valid session, I would expect
to get the session values but I don't. @session and @env seem to
generate errors.

I have this code in error_mailer.rb

<% for key, val in @session -%>
  <p><b><%= key %></b></p>
  <p><%= val.to_yaml.to_a.join("</p>\n<p> ") %></p>
<% end -%>

and similar for @env but both return empty sections.

but similar using @params does return values.

----
something changed in Rails 2.3.2 and @params and @env are good but
@session seems to be nil - even when there is an active session.

If someone wants to toss me a bone here, I will adjust my code but for
now, I just commented out the @session section so I can move on.

Session handling was in large part rewritten for 2.3.2 - assumptions
like there being an instance variable called @data almost certainly
no longer hold.

Fred

> ----
> something changed in Rails 2.3.2 and @params and @env are good but
> @session seems to be nil - even when there is an active session.
>
> If someone wants to toss me a bone here, I will adjust my code but for
> now, I just commented out the @session section so I can move on.

Session handling was in large part rewritten for 2.3.2 - assumptions
like there being an instance variable called @data almost certainly
no longer hold.

so it appears that
session.instance_variable_get("@data")

gets me nothing of value and I wanted the current session hash here,
but
I don't know how to get this from the changed Rails.

Yes, this is definitely changed in Rails 2.3 and pretty much every
error
notification I have found on the Internet now is broken.

If I were you I'd stick a breakpoint somewhere around there and fiddle
with the session object to see what it's got.

Fred