Exception: MSIDP::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/msidp/error.rb

Overview

Error from Microsoft identity platform.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.

Parameters:

  • response (Net::HTTPResponse)

    the HTTP response



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msidp/error.rb', line 17

def initialize(response)
  @response = response
  if response.content_type&.start_with? 'application/json'
    @body = JSON.parse(response.body, symbolize_names: true)
    @error = @body[:error]
    @description = @body[:error_description]
    super(<<-"MSG"
      #{response.code}: #{response.message}
      #{@error}: #{@description}
    MSG
    )
  else
    @body = response.body
    super(<<-"MSG"
      #{response.code}: #{response.message}
      #{@body}
    MSG
    )
  end
end

Instance Attribute Details

#bodyString, Hash (readonly)

Returns the parsed body of the HTTP response in JSON case, otherwise the raw body.

Returns:

  • (String, Hash)

    the parsed body of the HTTP response in JSON case, otherwise the raw body.



10
11
12
# File 'lib/msidp/error.rb', line 10

def body
  @body
end

#descriptionString (readonly)

Returns the error description.

Returns:

  • (String)

    the error description



14
15
16
# File 'lib/msidp/error.rb', line 14

def description
  @description
end

#errorString (readonly)

Returns the error code.

Returns:

  • (String)

    the error code



12
13
14
# File 'lib/msidp/error.rb', line 12

def error
  @error
end

#responseNet::HTTPResponse (readonly)

Returns the HTTP response.

Returns:

  • (Net::HTTPResponse)

    the HTTP response



7
8
9
# File 'lib/msidp/error.rb', line 7

def response
  @response
end