Comments (7)
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.
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.
@smartinez87 what do you think? Am I doin' it wrong?
from exception_notification.
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.
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.
(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.
@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)
- No way to tell which rails environment the error came from
- Error on Rails 6.1 for Rails.application.class.parent_name.underscore HOT 2
- SNS Notifier Data Attribute
- New exception to add to ignored_exceptions HOT 2
- Secret_key_base is leaking through the email HOT 5
- link in the readme IS NOT AVAILABLE HOT 1
- Access to env through `notification_trigger` callback
- Add ability to control how exceptions are grouped for error_grouping HOT 1
- HTTP Authorization Header
- Additional data doesn't show in teams notification HOT 3
- Ignore_notifier_if settings are not respected in non-Rack usages such as background jobs. HOT 1
- Rails 7 is out ! HOT 4
- Psych 4 incompatible HOT 1
- Update rubocop configuration
- Gem's package includes `examples` directory
- Rails 7 API only exception not working HOT 3
- Google Chat is not sending error notification
- Can't find stack trace in the email notification HOT 1
- Error counts for grouped exception notifications are updated inconsistently, causing duplicate alerts
- Add new default exception to ignore for Rack::Utils::InvalidParameterError
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exception_notification.