Exception: Dinie::APIStatusError

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

Overview

The API returned a non-2xx response. Base of the openapi-mirrored marker catalog (‘generated/errors/registry.rb`); the markers are empty subclasses and inherit this constructor, so Internal::Errors.from_response can build any of them uniformly.

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)


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

#bodyHash, ... (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

#detailString? (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

#headersHash (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

#instanceString? (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

#statusInteger (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

#titleString? (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

#typeString? (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.

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