class Gapic::Rest::Error
Gapic
REST exception class
Attributes
status_code[R]
@return [Integer] the http status code for the error
Public Class Methods
new(message, status_code)
click to toggle source
@param message [String, nil] error message @param status_code
[Integer, nil] HTTP status code of this error
Calls superclass method
# File lib/gapic/rest/error.rb, line 28 def initialize message, status_code @status_code = status_code super message end
wrap_faraday_error(err)
click to toggle source
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
# File lib/gapic/rest/error.rb, line 39 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
Private Class Methods
try_parse_from_body(body_str)
click to toggle source
Tries to get the error information from the JSON bodies
@param body_str [String] @return [Array(String, String)]
# File lib/gapic/rest/error.rb, line 59 def try_parse_from_body body_str body = JSON.parse body_str return [nil, nil] unless body && body["error"].is_a?(Hash) message = body["error"]["message"] code = body["error"]["code"] [message, code] rescue JSON::ParserError [nil, nil] end