2015-04-17 00:28:38 +00:00
|
|
|
# Copyright 2015 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
module Google
|
|
|
|
module Apis
|
|
|
|
# Base error, capable of wrapping another
|
|
|
|
class Error < StandardError
|
2015-07-20 19:36:13 +00:00
|
|
|
attr_reader :status_code
|
|
|
|
attr_reader :header
|
|
|
|
attr_reader :body
|
2016-05-29 10:51:36 +00:00
|
|
|
|
2015-07-20 19:36:13 +00:00
|
|
|
def initialize(err, status_code: nil, header: nil, body: nil)
|
2015-04-17 00:28:38 +00:00
|
|
|
@cause = nil
|
|
|
|
|
|
|
|
if err.respond_to?(:backtrace)
|
|
|
|
super(err.message)
|
|
|
|
@cause = err
|
|
|
|
else
|
|
|
|
super(err.to_s)
|
|
|
|
end
|
2015-07-20 19:36:13 +00:00
|
|
|
@status_code = status_code
|
|
|
|
@header = header.dup unless header.nil?
|
|
|
|
@body = body
|
2015-04-17 00:28:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def backtrace
|
|
|
|
if @cause
|
|
|
|
@cause.backtrace
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-29 10:51:36 +00:00
|
|
|
|
2015-04-17 00:28:38 +00:00
|
|
|
# An error which is raised when there is an unexpected response or other
|
|
|
|
# transport error that prevents an operation from succeeding.
|
|
|
|
class TransmissionError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# An exception that is raised if a redirect is required
|
|
|
|
#
|
|
|
|
class RedirectError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# A 4xx class HTTP error occurred.
|
|
|
|
class ClientError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# A 4xx class HTTP error occurred.
|
|
|
|
class RateLimitError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# A 401 HTTP error occurred.
|
|
|
|
class AuthorizationError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# A 5xx class HTTP error occurred.
|
|
|
|
class ServerError < Error
|
|
|
|
end
|
|
|
|
|
|
|
|
# Error class for problems in batch requests.
|
|
|
|
class BatchError < Error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|