Exception: Kloudless::Error
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Kloudless::Error
- Defined in:
- lib/kloudless/error.rb,
lib/kloudless/error.rb
Overview
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.
end
Direct Known Subclasses
AuthenticationRequiredError, BadGatewayError, BadRequestError, FolderNotEmptyError, ForbiddenError, GatewayTimeoutError, InsufficientStorageError, InternalErrorError, InvalidParametersError, InvalidParentFolderError, InvalidResourceTypeError, InvalidTokenError, LinkErrorError, MethodNotAllowedError, NamingConflictError, NotAcceptableError, NotFoundError, NotImplementedError, PermissionDeniedError, RequestFailedError, ServiceForbiddenError, ServiceNotAvailableError, ServiceUnauthorizedError, TooManyRequestsError, TooManyServiceRequestsError, UnauthorizedError, UnknownError, UnsupportedMediaTypeError
Constant Summary collapse
- 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 “#Kloudless::Error.$_$_.chomp: #Kloudless::Error.$_$_.classify$_.classify.chomp,”’
{ bad_request: BadRequestError, request_failed: RequestFailedError, invalid_parent_folder: InvalidParentFolderError, invalid_parameters: InvalidParametersError, invalid_resource_type: InvalidResourceTypeError, unauthorized: UnauthorizedError, service_unauthorized: ServiceUnauthorizedError, authentication_required: AuthenticationRequiredError, invalid_token: InvalidTokenError, folder_not_empty: FolderNotEmptyError, permission_denied: PermissionDeniedError, forbidden: ForbiddenError, service_forbidden: ServiceForbiddenError, not_found: NotFoundError, naming_conflict: NamingConflictError, too_many_requests: TooManyRequestsError, too_many_service_requests: TooManyServiceRequestsError, method_not_allowed: MethodNotAllowedError, not_acceptable: NotAcceptableError, internal_error: InternalErrorError, link_error: LinkErrorError, unsupported_media_type: UnsupportedMediaTypeError, not_implemented: NotImplementedError, bad_gateway: BadGatewayError, service_not_available: ServiceNotAvailableError, gateway_timeout: GatewayTimeoutError, insufficient_storage: InsufficientStorageError }
Instance Attribute Summary collapse
-
#conflicting_resource_id ⇒ Object
Public: identitifer of resource request conflicted with.
-
#error_code ⇒ Object
Public: short string name of error.
-
#id ⇒ Object
Public: identifier of request that caused the error.
-
#status_code ⇒ Object
Public: e.g.
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Internal: ‘json` is a Hash.
Instance Attribute Details
#conflicting_resource_id ⇒ Object
Public: identitifer of resource request conflicted with. See 409.
27 28 29 |
# File 'lib/kloudless/error.rb', line 27 def conflicting_resource_id @conflicting_resource_id end |
#error_code ⇒ Object
Public: short string name of error. e.g. bad_request, request_failed
21 22 23 |
# File 'lib/kloudless/error.rb', line 21 def error_code @error_code end |
#id ⇒ Object
Public: identifier of request that caused the error
24 25 26 |
# File 'lib/kloudless/error.rb', line 24 def id @id end |
#status_code ⇒ Object
Public: e.g. 400, 401, 500, 4xx-5xx.
18 19 20 |
# File 'lib/kloudless/error.rb', line 18 def status_code @status_code end |
Class Method Details
.from_json(json) ⇒ Object
Internal: ‘json` is a Hash. Returns an instantiated subclass of Kloudless::Error.
31 32 33 34 35 36 37 38 39 |
# 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 |