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
Raised when Aylien Text API returns the HTTP status code 503
- TooManyRequests
Raised when Aylien Text API returns the HTTP status code 429
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
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
Initializes a new Error
object
@param message [Exception, String] @return [AylienTextApi::Error]
# File lib/aylien_text_api/error.rb, line 109 def initialize(message = '') super(message) end
Private Class Methods
# 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