Skip to content

Commit

Permalink
Introduce Kubeclient::ResourceNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Apr 23, 2017
1 parent 745a510 commit 6918f5a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rest-client'
require 'kubeclient/entity_list'
require 'kubeclient/http_error'
require 'kubeclient/resource_not_found_error'
require 'kubeclient/watch_notice'
require 'kubeclient/watch_stream'
require 'kubeclient/common'
Expand Down
3 changes: 2 additions & 1 deletion lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def handle_exception
{}
end
err_message = json_error_msg['message'] || e.message
raise Kubeclient::HttpError.new(e.http_code, err_message, e.response)
error_klass = e.http_code == 404 ? ResourceNotFoundError : HttpError
raise error_klass.new(e.http_code, err_message, e.response)
end

def discover
Expand Down
4 changes: 4 additions & 0 deletions lib/kubeclient/resource_not_found_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Kubeclient
class ResourceNotFoundError < HttpError
end
end
9 changes: 3 additions & 6 deletions test/test_guestbook_go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def test_create_guestbook_entities

def delete_namespace(client, namespace_name)
client.delete_namespace(namespace_name)
rescue Kubeclient::HttpError => exception
assert_instance_of(Kubeclient::HttpError, exception)
rescue Kubeclient::ResourceNotFoundError => exception
assert_equal(404, exception.error_code)
end

Expand Down Expand Up @@ -89,8 +88,7 @@ def delete_services(client, namespace, services)
# it's just a string - service name
client.delete_service(service, namespace)
end
rescue Kubeclient::HttpError => exception
assert_instance_of(Kubeclient::HttpError, exception)
rescue Kubeclient::ResourceNotFoundError => exception
assert_equal(404, exception.error_code)
end
end
Expand All @@ -106,8 +104,7 @@ def delete_replication_controllers(client, namespace, replication_controllers)
# it's just a string - rc name
client.delete_replication_controller(rc, namespace)
end
rescue Kubeclient::HttpError => exception
assert_instance_of(Kubeclient::HttpError, exception)
rescue Kubeclient::ResourceNotFoundError => exception
assert_equal(404, exception.error_code)
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/test_kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ def test_nonjson_exception

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')

exception = assert_raises(Kubeclient::HttpError) do
exception = assert_raises(Kubeclient::ResourceNotFoundError) do
client.get_services
end

assert_instance_of(Kubeclient::HttpError, exception)
assert(exception.message.include?('Not Found'))
assert_equal(404, exception.error_code)
end
Expand Down

0 comments on commit 6918f5a

Please sign in to comment.