Exception: RubyLokaliseApi::Error

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

Overview

Standard API errors

Defined Under Namespace

Classes: BadGateway, BadRequest, Conflict, ContentTooLarge, Forbidden, GatewayTimeout, Locked, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, TooManyRequests, Unauthorized

Constant Summary collapse

ClientError =
Class.new(self)
ServerError =
Class.new(self)
ERRORS =
{
  400 => RubyLokaliseApi::Error::BadRequest,
  401 => RubyLokaliseApi::Error::Unauthorized,
  403 => RubyLokaliseApi::Error::Forbidden,
  404 => RubyLokaliseApi::Error::NotFound,
  405 => RubyLokaliseApi::Error::MethodNotAllowed,
  406 => RubyLokaliseApi::Error::NotAcceptable,
  409 => RubyLokaliseApi::Error::Conflict,
  413 => RubyLokaliseApi::Error::ContentTooLarge,
  423 => RubyLokaliseApi::Error::Locked,
  429 => RubyLokaliseApi::Error::TooManyRequests,
  500 => RubyLokaliseApi::Error::ServerError,
  502 => RubyLokaliseApi::Error::BadGateway,
  503 => RubyLokaliseApi::Error::ServiceUnavailable,
  504 => RubyLokaliseApi::Error::GatewayTimeout
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '') ⇒ Error

Initializes a new Error object



82
83
84
# File 'lib/ruby_lokalise_api/error.rb', line 82

def initialize(message = '')
  super
end

Class Method Details

.from_response(body) ⇒ Object

Create a new error from an HTTP response



70
71
72
73
74
75
76
77
78
# File 'lib/ruby_lokalise_api/error.rb', line 70

def from_response(body)
  msg = if body.respond_to?(:key)
          body.key?('error') ? body['error']['message'] : body['message']
        else
          body
        end

  new msg.to_s
end