Exception: Zensana::Error

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil) ⇒ Error

Returns a new instance of Error.



13
14
15
# File 'lib/zensana/services/error.rb', line 13

def initialize(msg=nil)
  super msg || self.class.msg
end

Class Method Details

.handle_http_errors(http_response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zensana/services/error.rb', line 17

def self.handle_http_errors(http_response)
  body = JSON.parse(http_response.body)
  message = if body['errors']
              body['errors'].first['message']
            else
              body
            end
rescue
  nil
ensure
  case http_response.code
  when 200, 201 then return
  when 404 then raise NotFound, message
  when 401..403 then raise AccessDenied, message
  else raise Unprocessable, message
  end
end

.msgObject



9
10
11
# File 'lib/zensana/services/error.rb', line 9

def self.msg
  @msg
end

.msg=(msg) ⇒ Object



5
6
7
# File 'lib/zensana/services/error.rb', line 5

def self.msg=(msg)
  @msg = msg
end