Exception: Glassfrog::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/glassfrog/error.rb

Overview

Encapsulates GlassFrog HTTP errors.

Constant Summary collapse

ClientError =

Raised with a 4xx HTTP status code

Class.new(self)
BadRequest =

Raised with the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised with the HTTP status code 401

Class.new(ClientError)
Forbidden =

Raised with the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised with the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised with the HTTP status code 406

Class.new(ClientError)
UnprocessableEntity =

Raised with the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised with the HTTP status code 429

Class.new(ClientError)
ServerError =

Raised with a 5xx HTTP status code

Class.new(self)
InternalServerError =

Raised with the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised with the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised with the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised with the HTTP status code 504

Class.new(ServerError)
ERRORS =
{
  400 => Glassfrog::Error::BadRequest,
  401 => Glassfrog::Error::Unauthorized,
  403 => Glassfrog::Error::Forbidden,
  404 => Glassfrog::Error::NotFound,
  406 => Glassfrog::Error::NotAcceptable,
  422 => Glassfrog::Error::UnprocessableEntity,
  429 => Glassfrog::Error::TooManyRequests,
  500 => Glassfrog::Error::InternalServerError,
  502 => Glassfrog::Error::BadGateway,
  503 => Glassfrog::Error::ServiceUnavailable,
  504 => Glassfrog::Error::GatewayTimeout,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', code = nil) ⇒ Glassfrog::Error

Initializes a new Error object.

Parameters:

  • message (defaults to: '')

    ” [String] Meaningful message about the error.

  • code (defaults to: nil)

    nil [Integer] The HTTP response code.



92
93
94
95
# File 'lib/glassfrog/error.rb', line 92

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

Instance Attribute Details

#codeInteger (readonly)

Returns:

  • (Integer)


7
8
9
# File 'lib/glassfrog/error.rb', line 7

def code
  @code
end

Class Method Details

.from_response(code, body, headers) ⇒ Glassfrog::Error

Create a new error from an HTTP response.

Parameters:

  • code (Integer)

    The HTTP response code.

  • body (String)

    The HTTP response body.

  • headers (Hash)

    The HTTP response headers.

Returns:



61
62
63
64
# File 'lib/glassfrog/error.rb', line 61

def from_response(code, body, headers)
  message = parse_error(code, body, headers)
  new(message, code)
end