# Copyright (C) 2015 Conjur Inc # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # Conjur::Error is not in the API v4 because it breaks backwards compatibility. # Try to load it, and if not there, patch it in. begin require 'conjur/error' rescue LoadError # old API version module Conjur # Error class lifted from v5 branch of conjur-api. # The base Conjur error class. Rescue it to catch errors generated by the Conjur services. class Error < RuntimeError # Create a new instance based on structured error info. # @param [String] body JSON error information # @return [Error, nil] the exception instance or nil if +body+ doesn't # contain valid error info def self.create body error = JSON.parse(body)['error'] kind = error['kind'] klass = const_defined?(kind) && const_get(kind) || self klass.new error rescue nil end # @!attribute [r] message # @return [String] human-readable error message, as returned by the Conjur service # @see #details def message @error['message'] end # @!attribute [r] details # @return error details, as returned by the Conjur service # @see #message def details @error['details'] end # @!attribute [r] kind # @return [String] error kind, as returned by the Conjur service # @note Usually it will equal the class name. def kind @error['kind'] end # Indicates that the looked up record does not exist. class RecordNotFound < Error # @!attribute [r] details # @return [Hash] error details: # - +'kind'+ of the searched object # - +'id'+ that is missing end # Indicates a missing argument for a method call. class MissingArgument < Error # @!attribute [r] details # @return [String] name of the missing argument end # Indicates a name or identifier clash. class UniqueConstraintViolation < Error # @!attribute [r] details # @return [Hash] error details: # - +'value'+ that caused the clash # - +'field'+ in which the clash occurred # - +'kind'+ of an object being manipulated end private def initialize error @error = error super message end end end end