Skip to content

Commit

Permalink
Fedora::Connection now returns the Fedora error in any ServerError me…
Browse files Browse the repository at this point in the history
…ssages
  • Loading branch information
flyingzumwalt committed Oct 18, 2010
1 parent 5dbfbc5 commit a367c57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions History.txt
Expand Up @@ -10,6 +10,8 @@ Added RDoc code comments for experimental features from version 1.2

Bug: MetadataDatastream.update_indexed_attributes doesn't get tripped up by attribute names wrapped in arrays (previously wrapping the symbol in an array would cause an error

Fedora::Connection now returns the Fedora error in any ServerError messages

1.2.2

Misc bug fixes
Expand Down
25 changes: 13 additions & 12 deletions lib/fedora/connection.rb
Expand Up @@ -19,7 +19,7 @@ def initialize(response, message = nil)
end

def to_s
"Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
"Failed with #{response.code} #{@message.to_s}"
end
end

Expand Down Expand Up @@ -155,29 +155,30 @@ def request(method, path, *arguments)

# Handles response and error codes from remote service.
def handle_response(response)
message = "Error from Fedora: #{response.body}"
case response.code.to_i
when 301,302
raise(Redirection.new(response))
when 200...400
response
when 400
raise(BadRequest.new(response))
raise(BadRequest.new(response, message))
when 401
raise(UnauthorizedAccess.new(response))
raise(UnauthorizedAccess.new(response, message))
when 403
raise(ForbiddenAccess.new(response))
raise(ForbiddenAccess.new(response, message))
when 404
raise(ResourceNotFound.new(response))
raise(ResourceNotFound.new(response, message))
when 405
raise(MethodNotAllowed.new(response))
raise(MethodNotAllowed.new(response, message))
when 409
raise(ResourceConflict.new(response))
raise(ResourceConflict.new(response, message))
when 422
raise(ResourceInvalid.new(response))
when 401...500
raise(ClientError.new(response))
raise(ResourceInvalid.new(response, message))
when 423...500
raise(ClientError.new(response, message))
when 500...600
raise(ServerError.new(response))
raise(ServerError.new(response, message))
else
raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
end
Expand Down Expand Up @@ -211,4 +212,4 @@ def authorization_header
(@site.user || @site.password ? { 'Authorization' => 'Basic ' + ["#{@site.user}:#{ @site.password}"].pack('m').delete("\r\n") } : {})
end
end
end
end

0 comments on commit a367c57

Please sign in to comment.