~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activeresource/lib/active_resource/exceptions.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module ActiveResource
 
2
  class ConnectionError < StandardError # :nodoc:
 
3
    attr_reader :response
 
4
 
 
5
    def initialize(response, message = nil)
 
6
      @response = response
 
7
      @message  = message
 
8
    end
 
9
 
 
10
    def to_s
 
11
      "Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
 
12
    end
 
13
  end
 
14
 
 
15
  # Raised when a Timeout::Error occurs.
 
16
  class TimeoutError < ConnectionError
 
17
    def initialize(message)
 
18
      @message = message
 
19
    end
 
20
    def to_s; @message ;end
 
21
  end
 
22
 
 
23
  # Raised when a OpenSSL::SSL::SSLError occurs.
 
24
  class SSLError < ConnectionError
 
25
    def initialize(message)
 
26
      @message = message
 
27
    end
 
28
    def to_s; @message ;end
 
29
  end
 
30
 
 
31
  # 3xx Redirection
 
32
  class Redirection < ConnectionError # :nodoc:
 
33
    def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
 
34
  end
 
35
 
 
36
  # 4xx Client Error
 
37
  class ClientError < ConnectionError; end # :nodoc:
 
38
 
 
39
  # 400 Bad Request
 
40
  class BadRequest < ClientError; end # :nodoc
 
41
 
 
42
  # 401 Unauthorized
 
43
  class UnauthorizedAccess < ClientError; end # :nodoc
 
44
 
 
45
  # 403 Forbidden
 
46
  class ForbiddenAccess < ClientError; end # :nodoc
 
47
 
 
48
  # 404 Not Found
 
49
  class ResourceNotFound < ClientError; end # :nodoc:
 
50
 
 
51
  # 409 Conflict
 
52
  class ResourceConflict < ClientError; end # :nodoc:
 
53
 
 
54
  # 410 Gone
 
55
  class ResourceGone < ClientError; end # :nodoc:
 
56
 
 
57
  # 5xx Server Error
 
58
  class ServerError < ConnectionError; end # :nodoc:
 
59
 
 
60
  # 405 Method Not Allowed
 
61
  class MethodNotAllowed < ClientError # :nodoc:
 
62
    def allowed_methods
 
63
      @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
 
64
    end
 
65
  end
 
66
end