# Error tracking

By default, RoRvsWild catches exceptions raised by requests and jobs.

##Configuration

###Send errors manually

From a begin / rescue block:

```ruby
begin
  # Your code ...
rescue => exception
  RorVsWild.record_error(exception)
end
```

Or:

```ruby
RorVsWild.catch_error { 1 / 0 }  # => #<ZeroDivisionError: divided by 0>
Add extra details
RorVsWild.record_error(exception, {something: "important"})
RorVsWild.catch_error(something: "important") { 1 / 0 }
```

###Pre-fill context

It is also possible to pre-fill this context data at the begining of each request or job:

```ruby
class ApplicationController < ActionController::Base
  before_action :prefill_error_context
  def prefill_error_context
    RorVsWild.merge_error_context(something: "important")
  end
end
```

### Rails error reporter

Is a common interface to [report errors](https://guides.rubyonrails.org/error_reporting.html#using-the-error-reporter) without coupling your code to a specific service.
You must have at least the agent version 1.10.0.
Here is an example:

```ruby
Rails.error.handle { 1 / 0 } # Same as RorVsWild.catch_error { 1 / 0 }

begin
  1 / 0
rescue => e
  Rails.error.report(e) # Same as RorVsWild.record_error(e)
end
```

###Ignore specific exceptions

Use the ignore_exceptions parameter:

```yaml
# config/rorvswild.yml
production:
  api_key: "API_KEY"
  ignore_exceptions:
    - ActionController::RoutingError
    - ZeroDivisionError
```

Or with an initializer:

```ruby
# config/initializers/rorvswild.rb
RorVsWild::Client.new(
  api_key: "API_KEY",
  ignore_exceptions: ["ActionController::RoutingError", "ZeroDivisionError"]
)
```

By default all exceptions returned by `ActionDispatch::ExceptionWrapper.rescue_responses` are ignored, because they are already handled by Rails.
Thus you receive less noise and can focus on real errors only.
However, if you would like to see all errors, such as HTTP malformed request, you have to explicitely set `ignore_exceptions` as an empty array:

```yaml
# config/rorvswild.yml
production:
  api_key: "API_KEY"
  ignore_exceptions: []
```

```ruby
# config/initializers/rorvswild.rb
RorVsWild::Client.new(api_key: "API_KEY", ignore_exceptions: [])
```

Here is a list of default ignored the exceptions that may vary depending on the version of Rails:

- AbstractController::ActionNotFound
- ActionController::BadRequest
- ActionController::InvalidAuthenticityToken
- ActionController::InvalidCrossOriginRequest
- ActionController::MethodNotAllowed
- ActionController::MissingExactTemplate
- ActionController::NotImplemented
- ActionController::ParameterMissing
- ActionController::RoutingError
- ActionController::UnknownFormat
- ActionController::UnknownHttpMethod
- ActionDispatch::Http::MimeNegotiation::InvalidType
- ActionDispatch::Http::Parameters::ParseError
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::StaleObjectError
- Rack::QueryParser::InvalidParameterError
- Rack::QueryParser::ParameterTypeError
