lib/onering/api.rb in onering-client-0.0.61 vs lib/onering/api.rb in onering-client-0.0.62

- old
+ new

@@ -23,11 +23,16 @@ end module Errors class Exception < ::Exception; end class NotConnected < Exception; end + class ClientError < Exception; end + class Unauthorized < ClientError; end + class Forbidden < ClientError; end + class NotFound < ClientError; end + class ServerError < Exception; end class ConnectionTimeout < Exception; end class AuthenticationMissing < Exception; end end @@ -91,10 +96,21 @@ end if rv.code >= 500 raise Errors::ServerError.new("HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message','') rescue ''}") elsif rv.code >= 400 - raise Errors::ClientError.new("HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message', '') rescue ''}") + message = "HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message', '') rescue ''}" + + case rv.code + when 401 + raise Errors::Unauthorized.new(message) + when 403 + raise Errors::Forbidden.new(message) + when 404 + raise Errors::NotFound.new(message) + else + raise Errors::ClientError.new(message) + end else rv end end \ No newline at end of file