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

.call(config:, message:, exception: nil, payload: {}, report: false) ⇒ 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

Returns:

  • (Net::HTTPResponse) —

    response from Diffend



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

def call(config:, message:, exception: nil, payload: {}, report: false)
  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(
      config,
      errors_url(config.project_id),
      exception_payload
    )
  end

  exit 1
end

.errors_url(project_id) ⇒ String

Provides diffend errors endpoint url

Parameters:

  • project_id (String) —

    diffend project_id

Returns:

  • (String) —

    diffend endpoint



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

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)


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

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