Class: Ksef::ProblemDetails
- Inherits:
-
Data
- Object
- Data
- Ksef::ProblemDetails
- Defined in:
- lib/ksef/problem_details.rb,
lib/ksef/problem_details.rb
Overview
Parsing and presentation for ProblemDetails.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- DEFAULTS =
Only
statusandraware common to every envelope; everything else is absent in at least one of them, so the builders below name only what they actually have. { status: nil, title: nil, detail: nil, instance: nil, timestamp: nil, trace_id: nil, entries: [].freeze, reason_code: nil, security: {}.freeze, raw: nil }.freeze
Instance Attribute Summary collapse
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#reason_code ⇒ Object
readonly
Returns the value of attribute reason_code.
-
#security ⇒ Object
readonly
Returns the value of attribute security.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#code ⇒ Integer?
The first KSeF error code, when the body carried one.
-
#details ⇒ Array<String>
Every detail message, across all entries.
-
#summary ⇒ String
A single line suitable for an exception message.
Instance Attribute Details
#detail ⇒ Object (readonly)
Returns the value of attribute detail
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def detail @detail end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def entries @entries end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def instance @instance end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def raw @raw end |
#reason_code ⇒ Object (readonly)
Returns the value of attribute reason_code
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def reason_code @reason_code end |
#security ⇒ Object (readonly)
Returns the value of attribute security
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def security @security end |
#status ⇒ Object (readonly)
Returns the value of attribute status
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def status @status end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def @timestamp end |
#title ⇒ Object (readonly)
Returns the value of attribute title
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def title @title end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id
12 13 14 |
# File 'lib/ksef/problem_details.rb', line 12 def trace_id @trace_id end |
Class Method Details
.parse(status:, body:) ⇒ Ksef::ProblemDetails
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ksef/problem_details.rb', line 42 def parse(status:, body:) return build(status: status, raw: body) unless body.is_a?(Hash) if body["exception"].is_a?(Hash) legacy_exception(status, body) elsif body["status"].is_a?(Hash) legacy_status(status, body) else problem_json(status, body) end end |
Instance Method Details
#code ⇒ Integer?
Returns the first KSeF error code, when the body carried one.
128 |
# File 'lib/ksef/problem_details.rb', line 128 def code = entries.first&.code |
#details ⇒ Array<String>
Returns every detail message, across all entries.
131 |
# File 'lib/ksef/problem_details.rb', line 131 def details = entries.flat_map(&:details) |
#summary ⇒ String
A single line suitable for an exception message.
136 137 138 139 140 141 |
# File 'lib/ksef/problem_details.rb', line 136 def summary lead = detail || title || entries.first&.description parts = [lead, *details.reject { |d| d == lead }].compact body = parts.empty? ? "HTTP #{status}" : parts.join(" ") code ? "[#{code}] #{body}" : body end |