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
Raised with the HTTP status code 503
- TooManyRequests
Raised with the HTTP status code 429
Raised with the HTTP status code 401
- UnprocessableEntity
Raised with the HTTP status code 422
Attributes
@return [Integer]
Public Class Methods
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
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
.
# File lib/glassfrog/error.rb, line 92 def initialize(message = '', code = nil) super(message) @code = code end
Private Class Methods
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