Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8390

Show
Ignore:
Timestamp:
12/14/07 23:09:46 (10 months ago)
Author:
david
Message:

Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) (closes #10326) [trek]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activeresource/CHANGELOG

    r8364 r8390  
    11*SVN* 
     2 
     3* Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 [trek] 
    24 
    35* Correct empty response handling.  #10445 [seangeo] 
  • trunk/activeresource/lib/active_resource/connection.rb

    r8364 r8390  
    2626  # 4xx Client Error 
    2727  class ClientError < ConnectionError; end # :nodoc: 
     28   
     29  # 400 Bad Request 
     30  class BadRequest < ClientError; end # :nodoc 
     31   
     32  # 401 Unauthorized 
     33  class UnauthorizedAccess < ClientError; end # :nodoc 
     34   
     35  # 403 Forbidden 
     36  class ForbiddenAccess < ClientError; end # :nodoc 
    2837   
    2938  # 404 Not Found 
     
    111120          when 200...400 
    112121            response 
     122          when 400 
     123            raise(BadRequest.new(response)) 
     124          when 401 
     125            raise(UnauthorizedAccess.new(response)) 
     126          when 403 
     127            raise(ForbiddenAccess.new(response)) 
    113128          when 404 
    114129            raise(ResourceNotFound.new(response)) 
  • trunk/activeresource/test/connection_test.rb

    r7719 r8390  
    3939    end 
    4040 
     41    # 400 is a bad request (e.g. malformed URI or missing request parameter) 
     42    assert_response_raises ActiveResource::BadRequest, 400 
     43 
     44    # 401 is an unauthorized request 
     45    assert_response_raises ActiveResource::UnauthorizedAccess, 401 
     46 
     47    # 403 is a forbidden requst (and authorizing will not help) 
     48    assert_response_raises ActiveResource::ForbiddenAccess, 403 
     49 
    4150    # 404 is a missing resource. 
    4251    assert_response_raises ActiveResource::ResourceNotFound, 404 
     
    5261 
    5362    # 4xx are client errors. 
    54     [401, 499].each do |code| 
     63    [402, 499].each do |code| 
    5564      assert_response_raises ActiveResource::ClientError, code 
    5665    end