Class: Fog::AzureRM::CustomAzureOperationError

Inherits:
MsRestAzure::AzureOperationError
  • Object
show all
Defined in:
lib/fog/azurerm/custom_fog_errors.rb

Overview

This is a custom Fog exception inherited from MsRestAzure::AzureOperationError

Instance Method Summary collapse

Constructor Details

#initialize(message, azure_exception) ⇒ CustomAzureOperationError

Returns a new instance of CustomAzureOperationError.



6
7
8
# File 'lib/fog/azurerm/custom_fog_errors.rb', line 6

def initialize(message, azure_exception)
  super(azure_exception.request, azure_exception.response, azure_exception.body, "Exception in #{message}")
end

Instance Method Details



10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/custom_fog_errors.rb', line 10

def print_subscription_limits_information
  request_method = @request.method
  subscription_id = @request.path_params['subscriptionId'] unless @request.path_params.nil?

  limit_value = remaining_subscription_request_limits(@response)

  puts "Subscription: '#{subscription_id}'. Request Method: '#{request_method}'. \nLimit Value: #{limit_value['header']}: #{limit_value['value']}\n" unless limit_value.empty?
end

#remaining_subscription_request_limits(response) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/azurerm/custom_fog_errors.rb', line 19

def remaining_subscription_request_limits(response)
  limit = {}
  # handles both read and write limits
  if response.headers.key? 'x-ms-ratelimit-remaining-subscription-resource-requests'
    limit['header'] = 'x-ms-ratelimit-remaining-subscription-resource-requests'
    limit['value'] = response.headers['x-ms-ratelimit-remaining-subscription-resource-requests']

  # limit for collection API calls
  elsif response.headers.key? 'x-ms-ratelimit-remaining-subscription-resource-entities-read'
    limit['header'] = 'x-ms-ratelimit-remaining-subscription-resource-entities-read'
    limit['value'] = response.headers['x-ms-ratelimit-remaining-subscription-resource-entities-read']

  # read requests limit
  elsif response.headers.key? 'x-ms-ratelimit-remaining-subscription-reads'
    limit['header'] = 'x-ms-ratelimit-remaining-subscription-reads'
    limit['value'] = response.headers['x-ms-ratelimit-remaining-subscription-reads']

  # write requests limit
  elsif response.headers.key? 'x-ms-ratelimit-remaining-subscription-writes'
    limit['header'] = 'x-ms-ratelimit-remaining-subscription-writes'
    limit['value'] = response.headers['x-ms-ratelimit-remaining-subscription-writes']
  end
  limit
end