Exception: Quicopt::QuicoptError

Inherits:
Error
  • Object
show all
Defined in:
lib/quicopt/client.rb

Overview

A non-2xx service response.

reason is the service's stable snake_case code (+size_exceeded+, unsupported_model, quota_exhausted, not_done, too_many_inflight, queue_full, parse_error, …) — match on it, not on the message. display is the framed text to print; status_code the HTTP status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, body) ⇒ QuicoptError

Returns a new instance of QuicoptError.



94
95
96
97
98
99
100
# File 'lib/quicopt/client.rb', line 94

def initialize(status_code, body)
  @status_code = status_code
  @body = body.is_a?(Hash) ? body : { "error" => body.to_s }
  @reason = @body["reason"]
  @display = @body["display"]
  super(@body["error"] || "HTTP #{status_code}")
end

Instance Attribute Details

#bodyHash (readonly)

Returns the decoded error body.

Returns:

  • (Hash)

    the decoded error body



88
89
90
# File 'lib/quicopt/client.rb', line 88

def body
  @body
end

#displayString? (readonly)

Returns the server-rendered, ready-to-print message.

Returns:

  • (String, nil)

    the server-rendered, ready-to-print message



92
93
94
# File 'lib/quicopt/client.rb', line 92

def display
  @display
end

#reasonString? (readonly)

Returns the stable machine-readable reason code.

Returns:

  • (String, nil)

    the stable machine-readable reason code



90
91
92
# File 'lib/quicopt/client.rb', line 90

def reason
  @reason
end

#status_codeInteger (readonly)

Returns the HTTP status code.

Returns:

  • (Integer)

    the HTTP status code



86
87
88
# File 'lib/quicopt/client.rb', line 86

def status_code
  @status_code
end