Skip to content

Update error handling to use body message instead of reason phrase #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/fog/proxmox/compute/models/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ def get(id)
status_data = service.get_server_status path_params
config_data = service.get_server_config path_params
rescue StandardError => e
if e.respond_to?('response') && e.response.respond_to?('data') && e.response.data.has_key?(:reason_phrase) && e.response.data[:reason_phrase].end_with?('does not exist')
raise(Fog::Errors::NotFound)
if e.respond_to?('response') && e.response.respond_to?('data') && e.response.data.has_key?(:body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handling body additionally, might be useful - but we still should catch the reason_pharse, too?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I explained in #108, the reason phrase should not be used for anything. It might be overwritten by intermediate servers or completely discarded.

begin
json = JSON.parse(e.response.body)
if json['message']&.include?('does not exist')
raise(Fog::Errors::NotFound)
end
rescue StandardError
raise e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the reason to to just re-raise an exception? is the exception handling then useful?

end
end

raise(e)
else
data = status_data.merge(config_data).merge(node: node_id, vmid: id)
Expand Down
Loading