Exception: Dinie::APIStatusError

Inherits:
APIError show all
Defined in:
lib/dinie/runtime/errors.rb,
sig/dinie/runtime/errors.rbs

Overview

The API returned a non-2xx response. Base of the openapi-mirrored marker catalog.

Instance Attribute Summary collapse

Attributes inherited from APIError

#code, #request_id

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, headers:, request_id: nil) ⇒ APIStatusError

Returns a new instance of APIStatusError.

Parameters:

  • status (Integer)
  • body (Hash, String, nil) —

    parsed Problem Details (symbol keys), raw text, or nil

  • headers (Hash)
  • request_id (String, nil) (defaults to: nil)
  • status: (Integer)
  • body: (Hash[Symbol, untyped], String, nil)
  • headers: (Hash[untyped, untyped])
  • request_id: (String, nil) (defaults to: nil)


73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dinie/runtime/errors.rb', line 73

def initialize(status:, body:, headers:, request_id: nil)
  @status = status
  @headers = headers
  @body = body
  problem = body.is_a?(Hash) ? body : nil
  @type = string_field(problem, :type)
  @title = string_field(problem, :title)
  @detail = string_field(problem, :detail)
  @instance = string_field(problem, :instance)
  super(self.class.build_message(status, body, request_id),
        code: string_field(problem, :code), request_id: request_id)
end

Instance Attribute Details

#body ⇒ Hash, ... (readonly)

Returns parsed Problem Details, raw body text, or nil.

Returns:

  • (Hash, String, nil) —

    parsed Problem Details, raw body text, or nil



59
60
61
# File 'lib/dinie/runtime/errors.rb', line 59

def body
  @body
end

#detail ⇒ String? (readonly)

Returns Problem Details detail.

Returns:

  • (String, nil) —

    Problem Details detail



65
66
67
# File 'lib/dinie/runtime/errors.rb', line 65

def detail
  @detail
end

#headers ⇒ Hash (readonly)

Returns raw response headers.

Returns:

  • (Hash) —

    raw response headers



57
58
59
# File 'lib/dinie/runtime/errors.rb', line 57

def headers
  @headers
end

#instance ⇒ String? (readonly)

Returns Problem Details instance.

Returns:

  • (String, nil) —

    Problem Details instance



67
68
69
# File 'lib/dinie/runtime/errors.rb', line 67

def instance
  @instance
end

#status ⇒ Integer (readonly)

Returns HTTP status code.

Returns:

  • (Integer) —

    HTTP status code



55
56
57
# File 'lib/dinie/runtime/errors.rb', line 55

def status
  @status
end

#title ⇒ String? (readonly)

Returns Problem Details title.

Returns:

  • (String, nil) —

    Problem Details title



63
64
65
# File 'lib/dinie/runtime/errors.rb', line 63

def title
  @title
end

#type ⇒ String? (readonly)

Returns Problem Details type URL.

Returns:

  • (String, nil) —

    Problem Details type URL



61
62
63
# File 'lib/dinie/runtime/errors.rb', line 61

def type
  @type
end

Class Method Details

.build_message(status, body, request_id) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • status (Integer)
  • body (Object)
  • request_id (String, nil)

Returns:

  • (String)


88
89
90
91
92
# File 'lib/dinie/runtime/errors.rb', line 88

def self.build_message(status, body, request_id)
  summary = message_summary(body)
  suffix = request_id.nil? ? "" : " (request_id: #{request_id})"
  summary ? "#{status} #{summary}#{suffix}" : "#{status} status code (no body)#{suffix}"
end

Instance Method Details

#string_field(problem, key) ⇒ String?

Parameters:

  • problem (Hash[Symbol, untyped], nil)
  • key (Symbol)

Returns:

  • (String, nil)


106
107
108
109
110
111
# File 'lib/dinie/runtime/errors.rb', line 106

def string_field(problem, key)
  return nil unless problem

  value = problem[key]
  value.is_a?(String) ? value : nil
end