class AylienTextApi::Error

Constants

BadGateway

Raised when Aylien Text API returns the HTTP status code 502

BadRequest

Raised when Aylien Text API returns the HTTP status code 400

ClientError

Raised when Aylien Text API returns a 4xx HTTP status code

ERRORS
Forbidden

Raised when Aylien Text API returns the HTTP status code 403

GatewayTimeout

Raised when Aylien Text API returns the HTTP status code 504

InternalServerError

Raised when Aylien Text API returns the HTTP status code 500

InvalidInput

Raised when Aylien Text API input is invalid

NotAcceptable

Raised when Aylien Text API returns the HTTP status code 406

NotFound

Raised when Aylien Text API returns the HTTP status code 404

PaymentRequired

Raised when Aylien Text API returns the HTTP status code 402

ServerError

Raised when Aylien Text API returns a 5xx HTTP status code

ServiceUnavailable

Raised when Aylien Text API returns the HTTP status code 503

TooManyRequests

Raised when Aylien Text API returns the HTTP status code 429

Unauthorized

Raised when Aylien Text API returns the HTTP status code 401

UnprocessableEntity

Raised when Aylien Text API returns the HTTP status code 422

Public Class Methods

from_response(response) click to toggle source

Create a new error from an HTTP response

@param response [HTTP::Response] @return [AylienTextApi::Error]

# File lib/aylien_text_api/error.rb, line 82
def from_response(response)
  body = if response["Content-Type"].include?('json')
    JSON.parse(response.body, :symbolize_names => true)
  else
    response.body
  end
  message = parse_error(body)
  new(message)
end
new(message = '') click to toggle source

Initializes a new Error object

@param message [Exception, String] @return [AylienTextApi::Error]

Calls superclass method
# File lib/aylien_text_api/error.rb, line 109
def initialize(message = '')
  super(message)
end

Private Class Methods

parse_error(body) click to toggle source
# File lib/aylien_text_api/error.rb, line 94
def parse_error(body)
  if body.nil? || body.empty?
    ''
  elsif body.is_a?(Hash) && body[:error]
    body[:error]
  else
    body
  end
end