class Kloudless::Error
All errors inherit from Kloudless::Error
. You may rescue this class as a catch all. Specific errors are documented in developers.kloudless.com/docs#errors
begin # ... some api action rescue Kloudless::Error => e $stderr.puts e.status_code # 401 $stderr.puts e.error_code # 'unauthorized' $stderr.puts e.id # id of request that caused the error $stderr.puts e.conflicting_resource_id $stderr.puts e.message end
Constants
- ERRORS
We could use ActiveSupport::Inflector here, but didn't want to bring in a dependency. To regenerate, copy from docs, and run:
pbpaste | ruby -r'active_support/core_ext/string/inflections' -ne 'puts “#{$_.chomp}: #{$_.classify.chomp},”'
Attributes
conflicting_resource_id[RW]
Public: identitifer of resource request conflicted with. See 409.
error_code[RW]
Public: short string name of error. e.g. bad_request, request_failed
id[RW]
Public: identifier of request that caused the error
status_code[RW]
Public: e.g. 400, 401, 500, 4xx-5xx.
Public Class Methods
from_json(json)
click to toggle source
Internal: `json` is a Hash. Returns an instantiated subclass of Kloudless::Error
.
# File lib/kloudless/error.rb, line 31 def self.from_json(json) error_class = ERRORS.fetch(json["error_code"].to_sym, UnknownError) error = error_class.new(json["message"]) error.error_code = json["error_code"] error.status_code = json["status_code"] error.id = json["id"] error.conflicting_resource_id = json["conflicting_resource_id"] error end