# Error Reporting API - Class Google::Cloud::ErrorReporting::Middleware (v0.45.1)

0.45.1 (latest) 0.45.0 0.44.0 0.43.0 0.42.3 Reference documentation and code samples for the Error Reporting API class Google::Cloud::ErrorReporting::Middleware.

## Middleware

Google::Cloud::ErrorReporting::Middleware defines a Rack Middleware
that can automatically catch upstream exceptions and report them
to Error Reporting.

## Inherits

- Object

## Methods

### #call

    def call(env)

Implements the mandatory Rack Middleware call method.


<br />

Catch all Exceptions from upstream and report them to
Error Reporting. Unless the exception's class is defined to be ignored
by this Middleware.
**Parameter**

- **env** (Hash) --- Rack environment hash

### #error_event_from_exception

    def error_event_from_exception(env, exception) -> Google::Cloud::ErrorReporting::ErrorEvent

Creates a [ErrorEvent](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting-ErrorEvent "Google::Cloud::ErrorReporting::ErrorEvent (class)") based on the
exception. Fill in the HttpRequestContext section of the ErrorEvent
based on the HTTP Request headers.


<br />

When used in Rails environment. It replies on
ActionDispatch::ExceptionWrapper class to derive a HTTP status code
based on the exception's class.
**Parameters**

- **env** (Hash) --- Rack environment hash
- **exception** (Exception) --- Exception to convert from
**Returns**

- ([Google::Cloud::ErrorReporting::ErrorEvent](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting-ErrorEvent)) --- The gRPC ErrorEvent object that's based on given env and exception

### #error_reporting

    def error_reporting()

A Google::Cloud::ErrorReporting::Project client used to report
error events.

### #initialize

    def initialize(app, error_reporting: nil, **kwargs) -> Google::Cloud::ErrorReporting::Middleware

Construct a new instance of Middleware.
**Parameters**

- **app** (Rack::Application) --- The Rack application
- **error_reporting** ([Google::Cloud::ErrorReporting::Project](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting-Project)) *(defaults to: nil)* --- A Google::Cloud::ErrorReporting::Project client for reporting exceptions
- **kwargs** (Hash) --- Hash of configuration settings. Used for backward API compatibility. See the [Configuration
  Guide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html) for the prefered way to set configuration parameters.
**Returns**

- ([Google::Cloud::ErrorReporting::Middleware](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-error_reporting/latest/Google-Cloud-ErrorReporting-Middleware)) --- A new instance of Middleware

### #report_exception

    def report_exception(env, exception)

Report an given exception to Error Reporting.


<br />

While it reports most of the exceptions. Certain Rails exceptions that
maps to a HTTP status code less than 500 will be treated as not the
app fault and ignored.
**Parameters**

- **env** (Hash) --- Rack environment hash
- **exception** (Exception) --- The Ruby exception to report.

## Constants

### EXCEPTION_KEYS

**value:**\["sinatra.error", "rack.exception"\].freeze