I need to create exceptions that do something already by default and have the same behavior as Standarterror

Asked

Viewed 22 times

0

Hello,

I work with Rails and use Sentry to log errors from my applications automatically. When an exception is thrown the error is not generated, so I have to force the error capture through the command:

Raven.captureMessage(e.message, level: 'error')

However I would not like that in almost every Exception have to repeat this line.

I tried to create a class to avoid repetition, but I ended up not succeeding, follow my attempt (file created in lib/raven_error.Rb):

class RavenError < StandardError
    def initialize exception
        super
        Raven.captureMessage(exception.message, level: 'error')
    end
end

Sample controller:

    def create
    @user = User.new(user_params)

    begin
        @user.save
    rescue RavenError => e
        render :new
    end

I would like the captureMessage method to be executed when instantiating the Ravenerror exception, without having to order inside every.

  • Apparently Raven/Sentry does not implement auto exception capture. If you can still change, I recommend Bugsnag.

  • It automatically captures, but inside a Try catch it does not think it is an error, because the validation is treated and the system does not generate log, so in this type of case it needs to call manually.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.