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.



153
154
155
156
157
158
159
# File 'lib/quicopt/client.rb', line 153

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

#body ⇒ Hash (readonly)

Returns the decoded error body.

Returns:

  • (Hash) —

    the decoded error body



147
148
149
# File 'lib/quicopt/client.rb', line 147

def body
  @body
end

#display ⇒ String? (readonly)

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

Returns:

  • (String, nil) —

    the server-rendered, ready-to-print message



151
152
153
# File 'lib/quicopt/client.rb', line 151

def display
  @display
end

#reason ⇒ String? (readonly)

Returns the stable machine-readable reason code.

Returns:

  • (String, nil) —

    the stable machine-readable reason code



149
150
151
# File 'lib/quicopt/client.rb', line 149

def reason
  @reason
end

#status_code ⇒ Integer (readonly)

Returns the HTTP status code.

Returns:

  • (Integer) —

    the HTTP status code



145
146
147
# File 'lib/quicopt/client.rb', line 145

def status_code
  @status_code
end