Class: ActiveResource::ClientError

Inherits:
ConnectionError
  • Object
show all
Defined in:
lib/liquidplanner/ext/exceptions.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ ClientError

Extend client errors so that they annotate the response message with the details from a JSON response. LiquidPlanner sends back useful response bodies, so we might as well use them if they are available.



8
9
10
11
12
13
14
15
16
# File 'lib/liquidplanner/ext/exceptions.rb', line 8

def initialize(response, message=nil)
  if !message && response['Content-Type']['application/json']
    details = ActiveSupport::JSON.decode(response.body)
    detailed_message = details['message']
    super response, detailed_message
  else
    super response, message
  end
end

Instance Method Details

#to_sObject

Return the default exception message with the extracted API message as well if available



19
20
21
22
23
# File 'lib/liquidplanner/ext/exceptions.rb', line 19

def to_s
  str = super
  str << "  #{@message}" if @message
  str
end