Class: CircuitClient::ClientError

Inherits:
Faraday::ClientError
  • Object
show all
Defined in:
lib/circuit_client/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(ex, response = nil) ⇒ ClientError

Returns a new instance of ClientError.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/circuit_client/errors.rb', line 5

def initialize(ex, response = nil)
  content_type = ex[:headers]['Content-Type']
  if !content_type.nil? && content_type.match(/application\/json/)
    begin
      error = JSON.parse(ex[:body])
      super("server response: #{error.to_json} (status: #{ex[:status]})")
    rescue JSON::ParserError
      super("server response with status #{ex[:status]} and malformed JSON")
    end
  else
    super(ex, response)
  end
end