Sha256: 074407661ec329e2d45a232239db30a7a68286e85a747b0f36a95620fd09c6d8
Contents?: true
Size: 1.23 KB
Versions: 9
Compression:
Stored size: 1.23 KB
Contents
module VkontakteApi # An exception raised by `VkontakteApi::Result` when given a response with an error. class Error < StandardError # An error code. # @return [Fixnum] attr_reader :error_code # An exception is initialized by the data from response mash. # @param [Hash] data Error data. def initialize(data) @error_code = data.error_code @error_msg = data.error_msg request_params = parse_params(data.request_params) @method_name = request_params.delete('method') @access_token = request_params.delete('access_token') @oauth = request_params.delete('oauth') @params = request_params end # A full description of the error. # @return [String] def message message = "VKontakte returned an error #{@error_code}: '#{@error_msg}'" message << " after calling method '#{@method_name}'" if @params.empty? message << " without parameters." else message << " with parameters #{@params.inspect}." end message end private def parse_params(params) params.inject({}) do |memo, pair| memo[pair[:key]] = pair[:value] memo end end end end
Version data entries
9 entries across 9 versions & 1 rubygems