Exception: Helium::Error

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

Overview

Custom error class for rescuing from Helium API errors

Direct Known Subclasses

ClientError

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Helium::Error

Returns the appropriate Helium::Error subclass based on status and response message

Parameters:

  • response (Typhoeus::Response)

Returns:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/helium/error.rb', line 10

def self.from_response(response)
  status  = response.code
  message = JSON.parse(response.body)["errors"].first["detail"]

  klass =  case status
           when 401   then Helium::InvalidApiKey
           else self
           end

  klass.new(message)
end