Exception: MLB::HTTPError

Inherits:
Error
  • Object
show all
Defined in:
lib/mlb/errors/http_error.rb

Overview

HTTP error raised when an API request fails

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ HTTPError

Initializes a new HTTPError instance

Examples:

HTTPError.new(response: response)

Parameters:

  • response (Net::HTTPResponse)

    the HTTP response



28
29
30
31
32
# File 'lib/mlb/errors/http_error.rb', line 28

def initialize(response:)
  super(response.message)
  @response = response
  @code = response.code
end

Instance Attribute Details

#codeString (readonly)

Returns the HTTP status code

Examples:

error.code #=> "404"

Returns:

  • (String)

    the HTTP status code



20
21
22
# File 'lib/mlb/errors/http_error.rb', line 20

def code
  @code
end

#responseNet::HTTPResponse (readonly)

Returns the HTTP response

Examples:

error.response #=> #<Net::HTTPNotFound 404 Not Found>

Returns:

  • (Net::HTTPResponse)

    the HTTP response



12
13
14
# File 'lib/mlb/errors/http_error.rb', line 12

def response
  @response
end