GithubHelp home page GithubHelp logo

Comments (7)

smartinez87 avatar smartinez87 commented on May 27, 2024

Hey,
not sure if I quite understood you, exceptions raised on a model are catched up by the gem without having to manually call exception_notification.
background_exception_notification is just for code that can't be reached within a request, like background tasks.

On the other hand, you're right and that piece of code is claiming for a refactor, so you're welcome to do so!

from exception_notification.

jjb avatar jjb commented on May 27, 2024

For example a model might access a third-party API or the filesystem, and I'd want to do something like this:

 begin
   # access the api
 rescue
   ExceptionNotifier::Notifier.background_exception_notification($!)
 end

from exception_notification.

jjb avatar jjb commented on May 27, 2024

@smartinez87 what do you think? Am I doin' it wrong?

from exception_notification.

smartinez87 avatar smartinez87 commented on May 27, 2024

sorry but I still don't understand...
say you have a a controller with something like this:

def some_action
  @user = User.find(params[:id])
  @user.my_model_method
end

and on the model

def my_model_action
  access the api
  update_some_data
end

Now, if something goes wrong there, it will automatically make the ExceptionNotification act and send you an email with the exception raised. Why should you manually invoke it?

from exception_notification.

jjb avatar jjb commented on May 27, 2024

Ah, whoops, I see that my example wasn't very good at all :-D. Here's something better:

def my_controller_action
  begin
    FooBarService.api(params[:stuff])
    @message_to_user = "It worked! Your FooBar has been connected!"
  rescue
    ExceptionNotifier::Notifier.background_exception_notification($!)
    @message_to_user =
      "The FooBar service is not available. Please try again later."
  ensure
    render 'remote_thingy_results'
  end
end

from exception_notification.

jjb avatar jjb commented on May 27, 2024

(I suppose one might say that this should be caught in a library and not in the controller -- even in that case I like to use ExceptionNotifier for logging the exceptions)

from exception_notification.

TylerRick avatar TylerRick commented on May 27, 2024

@jjb: It sounds like what you're trying to do is rescue an exception in your controller and still be able to use ExceptionNotifier to be notified of that exception that you rescued. I like to use ExceptionNotifier in this way too.

@smartinez87, the reason he has to manually invoke ExceptionNotifier is because he rescued the exception in his controller. The ExceptionNotifier middleware is only able to intercept and send notifications for exceptions that are _not_ rescued, because they have to bubble all the way up the middleware stack to ExceptionNotifier for it to become aware of them.

@jjb, I haven't used background_exception_notification before, but it sounds like in this case you could actually use the normal ExceptionNotifier::Notifier.exception_notification method instead, as mentioned in the "Manually notify of exception" section of the Readme. Also see how I'm doing it in #59.

You only need to use background_exception_notification if you _don't_ have access to request.env.

from exception_notification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.