Exception: OneRosterClient::Error

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

Overview

OneRosterClient error base class

Direct Known Subclasses

ClientError, ServerError, TimeoutError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil, message = nil) ⇒ Error

Create a new error

Parameters:

  • response (Typhoeus::Response) (defaults to: nil)
  • message (String) (defaults to: nil)

    Additional message info



32
33
34
35
36
37
38
39
# File 'lib/oneroster_client/error.rb', line 32

def initialize(response = nil, message = nil)
  @dependency_name = 'OneRoster'
  @response = { request: {} }
  @msg = message if message
  @original_response = response

  build_response if response
end

Instance Attribute Details

#dependency_nameString (readonly)

Frozen string representing the dependency raising the error

Returns:

  • (String)


27
28
29
# File 'lib/oneroster_client/error.rb', line 27

def dependency_name
  @dependency_name
end

#original_responseTyphoeus::Response (readonly)

The original response object via Typhoeus

Returns:

  • (Typhoeus::Response)


23
24
25
# File 'lib/oneroster_client/error.rb', line 23

def original_response
  @original_response
end

#responseHash (readonly)

Returns :status - Optional integer HTTP response status :headers - String key/value hash of HTTP response header

values.

:body - Optional string HTTP response body. :request - Hash

:method   - Symbol with the request HTTP method.
:url      - URI object with the url requested.
:url_path - String with the url path requested.
:params   - String key/value hash of query params
          present in the request.
:headers  - String key/value hash of HTTP request
          header values.
:body     - String HTTP request body.

Returns:

  • (Hash)

    :status - Optional integer HTTP response status :headers - String key/value hash of HTTP response header

    values.
    

    :body - Optional string HTTP response body. :request - Hash

    :method   - Symbol with the request HTTP method.
    :url      - URI object with the url requested.
    :url_path - String with the url path requested.
    :params   - String key/value hash of query params
              present in the request.
    :headers  - String key/value hash of HTTP request
              header values.
    :body     - String HTTP request body.
    


19
20
21
# File 'lib/oneroster_client/error.rb', line 19

def response
  @response
end

Instance Method Details

#messageObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/oneroster_client/error.rb', line 46

def message
  if @msg.nil?
    msg = "Error message: the server returned an error"
  else
    msg = @msg
  end

  msg += "\nHTTP status code: #{@response[:status]}" if @response[:status]
  msg += "\nResponse headers: #{@response[:headers]}" if @response[:headers]
  msg += "\nResponse body: #{@response[:body]}" if @response[:body]
  msg
end

#to_sObject

Override to_s to display a friendly error message



42
43
44
# File 'lib/oneroster_client/error.rb', line 42

def to_s
  message
end