Exception: OrchestratorClient::ApiError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- OrchestratorClient::ApiError
- Defined in:
- lib/orchestrator_client/error.rb
Direct Known Subclasses
DependencyCycle, EmptyEnvironment, EmptyTarget, PuppetdbError, QueryError, UnauthorizedError, UnknownEnvironment, UnknownError, UnknownJob, ValidationError
Defined Under Namespace
Classes: DependencyCycle, EmptyEnvironment, EmptyTarget, PuppetdbError, QueryError, UnauthorizedError, UnknownEnvironment, UnknownError, UnknownJob, ValidationError
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, code) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(data, code) ⇒ ApiError
Returns a new instance of ApiError.
8 9 10 11 12 |
# File 'lib/orchestrator_client/error.rb', line 8 def initialize(data,code) @code = code @data = data super(data['msg']) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/orchestrator_client/error.rb', line 6 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/orchestrator_client/error.rb', line 6 def data @data end |
Class Method Details
.make_error_from_response(res) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/orchestrator_client/error.rb', line 14 def self.make_error_from_response(res) begin data = JSON.parse(res.body) rescue return OrchestratorClient::BadResponse.new("Response body was not valid JSON: #{res.body}") end code = res.status case data['kind'] when 'puppetlabs.validators/validation-error' ValidationError.new(data, code) when 'puppetlabs.orchestrator/unknown-job' UnknownJob.new(data, code) when 'puppetlabs.orchestrator/unknown-environment' UnknownEnvironment.new(data, code) when 'puppetlabs.orchestrator/empty-environment' EmptyEnvironment.new(data, code) when 'puppetlabs.orchestrator/empty-target' EmptyTarget.new(data, code) when 'puppetlabs.orchestrator/dependency-cycle' DependencyCycle.new(data, code) when 'puppetlabs.orchestrator/puppetdb-error' PuppetdbError.new(data, code) when 'puppetlabs.orchestrator/query-error' QueryError.new(data, code) when 'puppetlabs.orchestrator/unknown-error' UnknownError.new(data, code) when 'puppetlabs.orchestrator/not-permitted' UnauthorizedError.new(data, code) else OrchestratorClient::ApiError.new(data, code) end end |