Exception: Gapic::Rest::Error

Inherits:
Common::Error show all
Defined in:
lib/gapic/rest/error.rb

Overview

Gapic REST exception class

Direct Known Subclasses

DeadlineExceededError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code, status: nil, details: nil, headers: nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • message (String, nil)

    error message

  • status_code (Integer, nil)

    HTTP status code of this error

  • status (String, nil) (defaults to: nil)

    The text representation of status as parsed from the response body

  • details (Object, nil) (defaults to: nil)

    Details data of this error

  • headers (Object, nil) (defaults to: nil)

    Http headers data of this error



45
46
47
48
49
50
51
# File 'lib/gapic/rest/error.rb', line 45

def initialize message, status_code, status: nil, details: nil, headers: nil
  super message
  @status_code = status_code
  @status = status
  @details = details
  @headers = headers
end

Instance Attribute Details

#detailsObject? (readonly) Also known as: status_details

Returns the details as parsed from the response body.

Returns:

  • (Object, nil)

    the details as parsed from the response body



30
31
32
# File 'lib/gapic/rest/error.rb', line 30

def details
  @details
end

#headersObject? (readonly) Also known as: header

Returns the headers of the REST error.

Returns:

  • (Object, nil)

    the headers of the REST error



34
35
36
# File 'lib/gapic/rest/error.rb', line 34

def headers
  @headers
end

#statusObject? (readonly)

Returns the text representation of status as parsed from the response body.

Returns:

  • (Object, nil)

    the text representation of status as parsed from the response body



28
29
30
# File 'lib/gapic/rest/error.rb', line 28

def status
  @status
end

#status_codeInteger? (readonly)

Returns the http status code for the error.

Returns:

  • (Integer, nil)

    the http status code for the error



26
27
28
# File 'lib/gapic/rest/error.rb', line 26

def status_code
  @status_code
end

Class Method Details

.wrap_faraday_error(err) ⇒ Gapic::Rest::Error

This creates a new error message wrapping the Faraday's one. Additionally it tries to parse and set a detailed message and an error code from from the Google Cloud's response body

Parameters:

  • err (Faraday::Error)

    the Faraday error to wrap

Returns:



62
63
64
65
# File 'lib/gapic/rest/error.rb', line 62

def wrap_faraday_error err
  message, status_code, status, details, headers = parse_faraday_error err
  Gapic::Rest::Error.new message, status_code, status: status, details: details, headers: headers
end