Exception: JsonapiErrorsHandler::Errors::StandardError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/jsonapi_errors_handler/errors/standard_error.rb

Overview

Handles serialization of Unexpected HTTP error (500 status code) It’s also a fallback for not mapped errors in the application.

Direct Known Subclasses

Forbidden, Invalid, NotFound, Unauthorized

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, status: nil, detail: nil, message: nil, source: {}) ⇒ StandardError

Returns a new instance of StandardError.



11
12
13
14
15
16
17
18
19
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 11

def initialize(
  title: nil, status: nil, detail: nil, message: nil, source: {}
)
  @title = title || 'Something went wrong'
  @detail = detail || message
  @detail ||= "We've encountered unexpected error, but our developers had been already notified about it" # rubocop:disable Metrics/LineLength
  @status = status || 500
  @source = KeysStringifier.call(source)
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



38
39
40
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 38

def detail
  @detail
end

#sourceObject (readonly)

Returns the value of attribute source.



38
39
40
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 38

def source
  @source
end

#statusObject (readonly)

Returns the value of attribute status.



38
39
40
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 38

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



38
39
40
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 38

def title
  @title
end

Instance Method Details

#serializable_hashObject



21
22
23
24
25
26
27
28
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 21

def serializable_hash
  {
    status: status.to_s,
    title: title,
    detail: detail,
    source: source
  }
end

#to_hObject



30
31
32
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 30

def to_h
  serializable_hash
end

#to_sObject



34
35
36
# File 'lib/jsonapi_errors_handler/errors/standard_error.rb', line 34

def to_s
  serializable_hash.to_s
end