mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-05 01:43:05 +00:00
[PR #11918/89d82ab9 backport][stable-12] scaleway: fix NoneType error in get_resources() (#11924)
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
---------
(cherry picked from commit 89d82ab9df)
Co-authored-by: RealCharlesChia <161665317+RealCharlesChia@users.noreply.github.com>
Co-authored-by: RealCharlesChia <RealCharlesChia@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
020fcb251f
commit
412a348738
2 changed files with 8 additions and 1 deletions
|
|
@ -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).
|
||||||
|
|
@ -237,10 +237,15 @@ class Scaleway:
|
||||||
results = self.get(f"/{self.name}")
|
results = self.get(f"/{self.name}")
|
||||||
|
|
||||||
if not results.ok:
|
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(
|
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)
|
return results.json.get(self.name)
|
||||||
|
|
||||||
def _url_builder(self, path, params):
|
def _url_builder(self, path, params):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue