Exception: Gapic::Rest::Error

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

Overview

Gapic REST exception class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code) ⇒ Error

Returns a new instance of Error.

Parameters:

  • message (String, nil)

    error message

  • status_code (Integer, nil)

    HTTP status code of this error



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

def initialize message, status_code
  @status_code = status_code
  super message
end

Instance Attribute Details

#status_codeInteger (readonly)

Returns the http status code for the error.

Returns:

  • (Integer)

    the http status code for the error



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

def status_code
  @status_code
end

Class Method Details

.wrap_faraday_error(err) ⇒ Object

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



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gapic/rest/error.rb', line 40

def wrap_faraday_error err
  message = err.message
  status_code = err.response_status

  if err.response_body
    msg, code = try_parse_from_body err.response_body
    message = "An error has occurred when making a REST request: #{msg}" unless msg.nil?
    status_code = code unless code.nil?
  end

  Gapic::Rest::Error.new message, status_code
end