Exception: Solace::Errors::HTTPError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/solace/errors/http_error.rb

Overview

Non-2xx HTTP or low-level network issues

Since:

  • 0.0.8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code:, body: nil) ⇒ HTTPError

Returns a new instance of HTTPError.

Parameters:

  • message (String)

    The error message

  • code (Integer)

    The HTTP status code

  • body (String) (defaults to: nil)

    The HTTP response body

Since:

  • 0.0.8



12
13
14
15
16
# File 'lib/solace/errors/http_error.rb', line 12

def initialize(message, code:, body: nil)
  super(message)
  @code = code
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Since:

  • 0.0.8



7
8
9
# File 'lib/solace/errors/http_error.rb', line 7

def body
  @body
end

#codeObject (readonly)

Since:

  • 0.0.8



7
8
9
# File 'lib/solace/errors/http_error.rb', line 7

def code
  @code
end

Class Method Details

.format_response(response) ⇒ Solace::Errors::HTTPError

Formats a response to an error

Parameters:

  • response (Net::HTTPResponse)

    The HTTP response

Returns:

Since:

  • 0.0.8



22
23
24
# File 'lib/solace/errors/http_error.rb', line 22

def self.format_response(response)
  new("HTTP error: #{response.message}", code: response.code.to_i, body: response.body)
end

.format_timeout_error(error) ⇒ Solace::Errors::HTTPError

Formats timeout errors

Parameters:

  • error (Net::OpenTimeout, Net::ReadTimeout)

    The timeout error

Returns:

Since:

  • 0.0.8



38
39
40
# File 'lib/solace/errors/http_error.rb', line 38

def self.format_timeout_error(error)
  new("HTTP timeout: #{error.class}", code: 408)
end

.format_transport_error(error) ⇒ Solace::Errors::HTTPError

Formats transport errors

Parameters:

  • error (SocketError, IOError)

    The transport error

Returns:

Since:

  • 0.0.8



30
31
32
# File 'lib/solace/errors/http_error.rb', line 30

def self.format_transport_error(error)
  new("HTTP transport error: #{error.message}", code: 0)
end