Sha256: 57063d2509a2bf37d9a38e1b454028189927baf876d8f7bcb033cc75c1d53e08
Contents?: true
Size: 1.2 KB
Versions: 13
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require 'calendly/error' module Calendly # Calendly apis client error object. class ApiError < 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
13 entries across 13 versions & 1 rubygems