Giter VIP home page Giter VIP logo

error_notifier's Introduction

ErrorNotifier

A tool for managing multiple error handlers. This decouples the error handling from the tools that is used to do so.

Installation

Add this line to your application's Gemfile:

gem 'error_notifier'

And then execute:

$ bundle

Or install it yourself as:

$ gem install error_notifier

Usage

This tools enables you to register multiple error handlers, and report to them appropriately.

It allows for decoupling between the tool used to notify errors, and where those errors are being notified.

It a single place to manage all of your error handling tools.

Example:

Registering a new tool:

# config/initializer.rb

ErrorNotifier.add_notifier(:my_notifier) do |exception, options|
  # Do something with the exception
  # Optional parameters can be passed in the options
end

# Example with NewRelic:
ErrorNotifier.add_notifier(:newrelic) do |exception, options|
  NewRelic::Agent.notice_error(exception)
end

# Example with Honeybader
ErrorNotifier.add_notifier(:honeybadger) do |exception, options|
  Honeybadger.notify_or_ignore(exception)
end

Then, in the actual code

begin
  # Do something that may raise an exception
rescue => e
  ErrorNotifier.notify(e)
end

Now suppose we wanted to add options, for specific handling of some tools, we could have the following in our initializer

# in an initializer
ErrorNotifier.add_notifier(:my_notifier) do |exception, options|
  MyNotifier.notify(exception, options[:my_notifier])
end

# in code
begin
  #...
rescue => e
  options = { my_notifier: 'Some Cool Hash' }
  ErrorNotifier.notify(e, options)
end

Now, the addition/removal of an existing tool can be done independently (loosely coupled) to the tool being used, while the granularity of error logging that each tool provides you with can be preserved.

Adding a custom tool

A custom tool can be added by responding to .call(error, options) where error is the error being raised.

Example:

class CustomNotifier
  def call(error, options)
    # Do something cool with the error and options
    # For now just print them
    Kernel.puts(error)
    Kernel.puts(options)
  end
end

ErrorNotifier.add_notifier(CustomNotifier)

Development

Link to RubyDocs

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/error_notifier.

License

The gem is available as open source under the terms of the MIT License.

error_notifier's People

Contributors

frankywahl avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.