Exception: Served::Resource::HttpError

Inherits:
Error show all
Defined in:
lib/served/resource/http_errors.rb

Direct Known Subclasses

ClientError, Redirection, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, resource, response) ⇒ HttpError

Returns a new instance of HttpError.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/served/resource/http_errors.rb', line 10

def initialize(code, resource, response)
  @code = code

  if resource.serializer.respond_to? :exception
    serialized = resource.serializer.exception(response.body).symbolize_keys!

    @error            = serialized[:error]
    @message          = serialized[:exception]
    @server_backtrace = serialized[:backtrace]
    @response         = OpenStruct.new(serialized) # TODO: remove in served 1.0, used for backwards compat

    super("An error '#{code} #{message}' occurred while making this request")
  else
    super "An error occurred '#{code}'"
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/served/resource/http_errors.rb', line 8

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/served/resource/http_errors.rb', line 6

def errors
  @errors
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/served/resource/http_errors.rb', line 4

def message
  @message
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/served/resource/http_errors.rb', line 7

def response
  @response
end

#server_backtraceObject (readonly)

Returns the value of attribute server_backtrace.



5
6
7
# File 'lib/served/resource/http_errors.rb', line 5

def server_backtrace
  @server_backtrace
end

Instance Method Details

#statusObject



27
28
29
# File 'lib/served/resource/http_errors.rb', line 27

def status
  self.class.status
end