Sha256: cab4d35a3dfb96612976fac53b651937fb60fdcac4b0912f5b619569564dd072
Contents?: true
Size: 1.18 KB
Versions: 3
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module Calendly # Calendly apis client error object. class ApiError < Calendly::Error # @return [Faraday::Response] attr_reader :response # @return [Integer] attr_reader :status # @return [String] attr_reader :title # @return [OAuth2::Error, JSON::ParserError] attr_reader :cause_exception def initialize(response, cause_exception, message: nil) @response = response @cause_exception = cause_exception @message = message set_attributes_from_response @message ||= cause_exception.message if cause_exception super @message end def inspect "\#<#{self.class}:#{object_id} title:#{title}, status:#{status}>" end private def set_attributes_from_response # rubocop:disable Metrics/CyclomaticComplexity return unless response return unless response.respond_to? :body @status = response.status if response.respond_to? :status parsed = JSON.parse response.body, symbolize_names: true @title = parsed[:title] || parsed[:error] @message ||= parsed[:message] || parsed[:error_description] rescue JSON::ParserError nil end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
calendly-0.2.0 | lib/calendly/api_error.rb |
calendly-0.1.3 | lib/calendly/api_error.rb |
calendly-0.1.2 | lib/calendly/api_error.rb |