Exception: Laposta::Error

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



22
23
24
25
# File 'lib/laposta/error.rb', line 22

def initialize(response)
  @response = response
  super("Response: #{response.inspect}\nBody: #{response.body}")
end

Class Method Details

.from_response(response) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/laposta/error.rb', line 3

def self.from_response(response)
  error_class = case response.status

    when 301 then LoginDoesNotExistError        # This login does not exist
    when 302 then InvalidPasswordError          # The password entered is incorrect
    when 303 then UserNotAllowedToLoginError    # This user is not (or no longer) allowed to log in
    when 304 then AccountNotAllowedToLoginError # This account is not (or no longer) allowed to log in
    when 305 then AccountNotVerifiedError       # This account has not been verified
    when 400 then BadRequestError               # Incomplete input
    when 401 then UnauthorizedError             # No valid API key was provided
    when 402 then RequestFailedError            # Input was in order, but request was not processed
    when 404 then NotFoundError                 # The requested object does not exist/could not be located
    when 429 then TooManyRequestsError          # The maximum number of requests was reached within the given unit of time
    when 500 then ServerError                   # Error detected on Laposta's side
    else self
    end
  error_class.new(response)
end