Sha256: e732b8fc282a4c186492c5b8a212e18ac8560ae27ae7d4330e6d3953e307f335

Contents?: true

Size: 525 Bytes

Versions: 19

Compression:

Stored size: 525 Bytes

Contents

# frozen_string_literal: true

class Freddy
  class ErrorResponse < StandardError
    DEFAULT_ERROR_MESSAGE = 'Use #response to get the error response'

    attr_reader :response

    def initialize(response)
      @response = response
      super(format_message(response) || DEFAULT_ERROR_MESSAGE)
    end

    private

    def format_message(response)
      return unless response.is_a?(Hash)

      message = [response[:error], response[:message]].compact.join(': ')
      message.empty? ? nil : message
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
freddy-2.8.0 lib/freddy/error_response.rb
freddy-2.7.0 lib/freddy/error_response.rb
freddy-2.6.0 lib/freddy/error_response.rb
freddy-2.5.1 lib/freddy/error_response.rb
freddy-2.5.0 lib/freddy/error_response.rb
freddy-2.5.0.pre.rc.1 lib/freddy/error_response.rb
freddy-2.4.0 lib/freddy/error_response.rb
freddy-2.3.0 lib/freddy/error_response.rb
freddy-2.2.4 lib/freddy/error_response.rb
freddy-2.2.3 lib/freddy/error_response.rb
freddy-2.2.2 lib/freddy/error_response.rb
freddy-2.2.1 lib/freddy/error_response.rb
freddy-2.2.0 lib/freddy/error_response.rb
freddy-2.1.0 lib/freddy/error_response.rb
freddy-2.0.0 lib/freddy/error_response.rb
freddy-1.7.0 lib/freddy/error_response.rb
freddy-1.6.0 lib/freddy/error_response.rb
freddy-1.5.0 lib/freddy/error_response.rb
freddy-1.4.2 lib/freddy/error_response.rb