From d6247a77943919f19249d681e403489c5b113501 Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Tue, 4 Dec 2018 13:06:24 -0700 Subject: [PATCH] Add custom inspect to Google::Apis:Error (#729) Add the status_code, header, and body values to inspect when present. These values can help users understand why they are getting errors, but many users don't know to look for them. Adding the values to inspect should help discoverability. --- lib/google/apis/errors.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/google/apis/errors.rb b/lib/google/apis/errors.rb index 0c8d053cf..85628f0a0 100644 --- a/lib/google/apis/errors.rb +++ b/lib/google/apis/errors.rb @@ -41,6 +41,15 @@ module Google super end end + + def inspect + extra = "" + extra << " status_code: #{status_code.inspect}" unless status_code.nil? + extra << " header: #{header.inspect}" unless header.nil? + extra << " body: #{body.inspect}" unless body.nil? + + "#<#{self.class.name}: #{message}#{extra}>" + end end # An error which is raised when there is an unexpected response or other