Exception: AylienTextApi::Error

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

Constant Summary collapse

ClientError =

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

Class.new(self)
InvalidInput =

Raised when Aylien Text API input is invalid

Class.new(ClientError)
BadRequest =

Raised when Aylien Text API returns the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised when Aylien Text API returns the HTTP status code 401

Class.new(ClientError)
PaymentRequired =

Raised when Aylien Text API returns the HTTP status code 402

Class.new(ClientError)
Forbidden =

Raised when Aylien Text API returns the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised when Aylien Text API returns the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised when Aylien Text API returns the HTTP status code 406

Class.new(ClientError)
UnprocessableEntity =

Raised when Aylien Text API returns the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised when Aylien Text API returns the HTTP status code 429

Class.new(ClientError)
ServerError =

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

Class.new(self)
InternalServerError =

Raised when Aylien Text API returns the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised when Aylien Text API returns the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised when Aylien Text API returns the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised when Aylien Text API returns the HTTP status code 504

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '') ⇒ AylienTextApi::Error

Initializes a new Error object

Parameters:

  • message (Exception, String) (defaults to: '')


109
110
111
# File 'lib/aylien_text_api/error.rb', line 109

def initialize(message = '')
  super(message)
end

Class Method Details

.from_response(response) ⇒ AylienTextApi::Error

Create a new error from an HTTP response

Parameters:

  • response (HTTP::Response)

Returns:



82
83
84
85
86
87
88
89
90
# 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