Module: Diffend::HandleErrors::Report

Defined in:
lib/diffend/handle_errors/report.rb

Overview

Module responsible for reporting errors to diffend

Class Method Summary collapse

Class Method Details

.build_request_object(config, payload) ⇒ Diffend::RequestObject

Parameters:

  • config (OpenStruct)

    diffend config

  • payload (Hash)

Returns:



37
38
39
40
41
42
43
44
# File 'lib/diffend/handle_errors/report.rb', line 37

def build_request_object(config, payload)
  Diffend::RequestObject.new(
    config: config,
    url: errors_url(config.project_id),
    payload: payload,
    request_method: :post
  )
end

.call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true) ⇒ Net::HTTPResponse

Execute request to Diffend

Parameters:

  • exception (Exception) (defaults to: nil)

    expection that was raised

  • payload (Hash) (defaults to: {})

    with versions to check

  • config (OpenStruct)

    Diffend config

  • message (Symbol)

    message that we want to display

  • report (Boolean) (defaults to: false)

    if true we will report the issue to diffend

  • raise_exception (Boolean) (defaults to: true)

    if true we will raise an exception

Returns:

  • (Net::HTTPResponse)

    response from Diffend

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/diffend/handle_errors/report.rb', line 18

def call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true)
  exception_payload = prepare_exception_payload(exception, payload)

  Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
  Bundler.ui.error(Diffend::HandleErrors::Messages.const_get(message.to_s.upcase))

  if report
    Diffend::Request.call(
      build_request_object(config, exception_payload)
    )
  end

  raise Diffend::Errors::HandledException if raise_exception
end

.errors_url(project_id) ⇒ String

Provides diffend errors endpoint url

Parameters:

  • project_id (String)

    diffend project_id

Returns:

  • (String)

    diffend endpoint



63
64
65
66
67
# File 'lib/diffend/handle_errors/report.rb', line 63

def errors_url(project_id)
  return ENV['DIFFEND_ERROR_URL'] if ENV.key?('DIFFEND_ERROR_URL')

  "https://my.diffend.io/api/projects/#{project_id}/errors"
end

.prepare_exception_payload(exception, payload) ⇒ Hash

Prepare exception payload and display it to stdout

Parameters:

  • exception (Exception)

    expection that was raised

  • payload (Hash)

    with versions to check

Returns:

  • (Hash)


52
53
54
55
56
# File 'lib/diffend/handle_errors/report.rb', line 52

def prepare_exception_payload(exception, payload)
  Diffend::HandleErrors::BuildExceptionPayload
    .call(exception, payload)
    .tap(&Diffend::HandleErrors::DisplayToStdout.method(:call))
end