class Glassfrog::Error

Encapsulates GlassFrog HTTP errors.

Constants

BadGateway

Raised with the HTTP status code 502

BadRequest

Raised with the HTTP status code 400

ClientError

Raised with a 4xx HTTP status code

ERRORS
Forbidden

Raised with the HTTP status code 403

GatewayTimeout

Raised with the HTTP status code 504

InternalServerError

Raised with the HTTP status code 500

NotAcceptable

Raised with the HTTP status code 406

NotFound

Raised with the HTTP status code 404

ServerError

Raised with a 5xx HTTP status code

ServiceUnavailable

Raised with the HTTP status code 503

TooManyRequests

Raised with the HTTP status code 429

Unauthorized

Raised with the HTTP status code 401

UnprocessableEntity

Raised with the HTTP status code 422

Attributes

code[R]

@return [Integer]

Public Class Methods

from_response(code, body, headers) click to toggle source

Create a new error from an HTTP response. @param code [Integer] The HTTP response code. @param body [String] The HTTP response body. @param headers [Hash] The HTTP response headers.

@return [Glassfrog::Error] The corresponding error for the code.

# File lib/glassfrog/error.rb, line 61
def from_response(code, body, headers)
  message = parse_error(code, body, headers)
  new(message, code)
end
new(message = '', code = nil) click to toggle source

Initializes a new Error object. @param message = ” [String] Meaningful message about the error. @param code = nil [Integer] The HTTP response code.

@return [Glassfrog::Error] The initialized Error.

Calls superclass method
# File lib/glassfrog/error.rb, line 92
def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Private Class Methods

parse_error(code, body, headers) click to toggle source

Returns a corresponding message for a GlassFrog error. @param code [Integer] The HTTP response code. @param body [String] The HTTP response body. @param headers [Hash] The HTTP response headers.

@return [String, Integer] A meaningful message or the error code.

# File lib/glassfrog/error.rb, line 75
def parse_error(code, body, headers)
  if body.content_type['mime_type'] == 'application/json' && body.parse['message']
    body.parse['message']
  elsif body.content_type['mime_type'] == 'text/html' && headers['Status']
    headers['Status']
  else 
    code
  end
end