Sha256: e9ff6ce3012b6d20b3fbcf67da51ae16e8449174a6cd15a4816e2fcac2b4db96

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

#--
# Copyright 2015 Google Inc. All rights reserved.
#
# 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.

require "gcloud/errors"

module Gcloud
  module Bigquery
    ##
    # Base BigQuery exception class.
    class Error < Gcloud::Error
    end

    ##
    # Raised when an API call is not successful.
    class ApiError < Error
      ##
      # The code of the error.
      attr_reader :code

      ##
      # The errors encountered.
      attr_reader :errors

      def initialize message, code, errors = [] #:nodoc:
        super message
        @code   = code
        @errors = errors
      end

      def self.from_response resp #:nodoc:
        if resp.data? && resp.data["error"]
          from_response_data resp.data["error"]
        else
          from_response_status resp
        end
      end

      def self.from_response_data error #:nodoc:
        new error["message"], error["code"], error["errors"]
      end

      def self.from_response_status resp #:nodoc:
        if resp.status == 404
          new "#{resp.error_message}: #{resp.request.uri.request_uri}",
              resp.status
        else
          new resp.error_message, resp.status
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gcloud-0.6.3 lib/gcloud/bigquery/errors.rb
gcloud-0.6.2 lib/gcloud/bigquery/errors.rb
gcloud-0.6.1 lib/gcloud/bigquery/errors.rb
gcloud-0.6.0 lib/gcloud/bigquery/errors.rb
gcloud-0.5.0 lib/gcloud/bigquery/errors.rb
gcloud-0.4.1 lib/gcloud/bigquery/errors.rb
gcloud-0.4.0 lib/gcloud/bigquery/errors.rb
gcloud-0.3.1 lib/gcloud/bigquery/errors.rb