Error Reporting API - Class Google::Cloud::ErrorReporting::Middleware (v0.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.

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 based on the exception. Fill in the HttpRequestContext section of the ErrorEvent based on the HTTP Request headers.

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

#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) (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 for the prefered way to set configuration parameters.
Returns

#report_exception

def report_exception(env, exception)

Report an given exception to Error Reporting.

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