Exception: Kitchen::Driver::Azure::OperationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/kitchen/driver/azure/errors.rb

Overview

Raised when Azure Resource Manager returns an error response.

Replaces MsRestAzure2::AzureOperationError, keeping the body accessor the driver's rescue blocks already rely on.

Note the explicit ::StandardError: Test Kitchen defines Kitchen::StandardError, and this class lives inside module Kitchen, so a bare StandardError here would resolve to that instead.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status: nil, body: {}) ⇒ OperationError

Returns a new instance of OperationError.

Parameters:

  • message (String)

    human-readable summary.

  • status (Integer) (defaults to: nil)

    HTTP status code.

  • body (Hash) (defaults to: {})

    parsed ARM error body.



31
32
33
34
35
# File 'lib/kitchen/driver/azure/errors.rb', line 31

def initialize(message, status: nil, body: {})
  super(message)
  @status = status
  @body = body
end

Instance Attribute Details

#bodyHash (readonly)

The parsed error body, as returned by ARM.

Returns:

  • (Hash)

    typically {"error" => {"code" => ..., "message" => ...}}.



21
22
23
# File 'lib/kitchen/driver/azure/errors.rb', line 21

def body
  @body
end

#statusInteger (readonly)

The HTTP status code of the failing response.

Returns:

  • (Integer)


26
27
28
# File 'lib/kitchen/driver/azure/errors.rb', line 26

def status
  @status
end

Instance Method Details

#codeString?

The Azure error code, when ARM supplied one.

Returns:

  • (String, nil)

    e.g. "DeploymentActive".



40
41
42
# File 'lib/kitchen/driver/azure/errors.rb', line 40

def code
  body.is_a?(Hash) ? body.dig("error", "code") : nil
end

#detailString?

Azure's own explanation, when ARM supplied one.

message is this class's summary of the request that failed; this is what Azure said about it, which is usually the part worth showing somebody.

Returns:

  • (String, nil)


51
52
53
# File 'lib/kitchen/driver/azure/errors.rb', line 51

def detail
  body.is_a?(Hash) ? body.dig("error", "message") : nil
end