mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-28 09:26:44 +00:00
scaleway: fix NoneType error in get_resources() (#11918)
* scaleway: fix NoneType error in get_resources() when API returns empty or non-JSON response * add changelog fragment for #11918 * Update changelogs/fragments/11361-scaleway-get-resources-none-type.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: RealCharlesChia <RealCharlesChia@users.noreply.github.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- scaleway_image_info, scaleway_ip_info, scaleway_organization_info, scaleway_security_group_info, scaleway_server_info, scaleway_snapshot_info, scaleway_volume_info - fix ``NoneType`` error when the Scaleway API returns an empty or non-JSON response body (https://github.com/ansible-collections/community.general/issues/11361, https://github.com/ansible-collections/community.general/pull/11918).
|
||||
@@ -240,10 +240,15 @@ class Scaleway:
|
||||
results = self.get(f"/{self.name}")
|
||||
|
||||
if not results.ok:
|
||||
api_response = results.json if results.json is not None else results.body
|
||||
message = api_response.get("message") if isinstance(api_response, dict) else api_response
|
||||
raise ScalewayException(
|
||||
f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {results.json['message']}]"
|
||||
f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {message}]"
|
||||
)
|
||||
|
||||
if results.json is None:
|
||||
raise ScalewayException(f"Scaleway API returned an empty or non-JSON response for {self.name}")
|
||||
|
||||
return results.json.get(self.name)
|
||||
|
||||
def _url_builder(self, path, params):
|
||||
|
||||
Reference in New Issue
Block a user