Exception: MsRest2::HttpOperationError

Inherits:
RestError
  • Object
show all
Defined in:
lib/ms_rest2/http_operation_error.rb

Overview

Class which represents an error meaning that either HTTP request or HTTP response was invalid.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ HttpOperationError

Creates and initialize new instance of the HttpOperationException class.

Parameters:

  • the (Hash)

    HTTP request data (uri, body, headers).

  • the (Faraday::Response)

    HTTP response object.

  • body (String)

    the HTTP response body.

  • error (String)

    message.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ms_rest2/http_operation_error.rb', line 28

def initialize(*args)
  @msg = self.class.name
  if args.size == 1
    # When only message is provided.
    @msg = args[0]
    super(args[0])
  elsif args.size == 2
    # When only request and response provided, body is nil.
    @request = args[0]
    @response = args[1]
    @body = nil
    super()
  elsif args.size == 3
    # When request, response and body were provided.
    @request = args[0]
    @response = args[1]
    @body = args[2]
    super()
  elsif args.size == 4
    # When request, response, body and message were provided.
    @request = args[0]
    @response = args[1]
    @body = args[2]
    @msg = args[3]
    super(args[3])
  else
    fail ArgumentError, 'Invalid number of arguments was provided, valid number: 1, 2, 3 or 4'
  end
end

Instance Attribute Details

#bodyString

Returns the HTTP response body.

Returns:

  • (String)

    the HTTP response body.



19
20
21
# File 'lib/ms_rest2/http_operation_error.rb', line 19

def body
  @body
end

#requestHash

Returns the HTTP request data (uri, body, headers).

Returns:

  • (Hash)

    the HTTP request data (uri, body, headers).



13
14
15
# File 'lib/ms_rest2/http_operation_error.rb', line 13

def request
  @request
end

#responseFaraday::Response

Returns the HTTP response object.

Returns:

  • (Faraday::Response)

    the HTTP response object.



16
17
18
# File 'lib/ms_rest2/http_operation_error.rb', line 16

def response
  @response
end

Instance Method Details

#to_json(*a) ⇒ Object



58
59
60
61
# File 'lib/ms_rest2/http_operation_error.rb', line 58

def to_json(*a)
  res_dict = response ? { body: response.body, headers: response.headers, status: response.status } : nil
  {message: @msg, request: request, response: res_dict}.to_json(*a)
end

#to_sObject



63
64
65
66
67
68
69
# File 'lib/ms_rest2/http_operation_error.rb', line 63

def to_s
  begin
    JSON.pretty_generate(self)
  rescue Exception => ex
    "#{self.class.name} failed in \n\t#{backtrace.join("\n\t")}"
  end
end