Sha256: 9a712c239942fddeb2a9fcf91d55a464b2639c9cb5cc46ab47c699182a78b9e6
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 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 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
calendly-0.1.1 | lib/calendly/api_error.rb |
calendly-0.1.0 | lib/calendly/api_error.rb |