Skip to content

chore: Improve error message if there is no organization with required name #425

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

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.28.0 [unreleased]

### Bug Fixes
1. [#425](https://github.com/influxdata/influxdb-client-python/pull/425): Improve error message if there is no `organization` with required `name`

## 1.27.0 [2022-03-18]

### Features
Expand Down
9 changes: 7 additions & 2 deletions influxdb_client/client/util/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def get_org_query_param(org, client, required_id=False):
"to determine their ID. Are you using token with sufficient permission?"
raise InfluxDBError(response=None, message=message)
return organizations[0].id
except ApiException:
return None
except ApiException as e:
if e.status == 404:
from influxdb_client.client.exceptions import InfluxDBError
message = f"The client cannot find organization with name: '{_org}' " \
"to determine their ID."
raise InfluxDBError(response=None, message=message)
raise e

return _org
5 changes: 3 additions & 2 deletions tests/test_Helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def test_required_id(self):
self.assertEqual(self.my_organization.id, org)

def test_required_id_not_exist(self):
org = get_org_query_param("not_exist_name", self.client, required_id=True)
self.assertIsNone(org)
with pytest.raises(InfluxDBError) as e:
get_org_query_param("not_exist_name", self.client, required_id=True)
assert "The client cannot find organization with name: 'not_exist_name' to determine their ID." in f"{e.value} "

def test_both_none(self):
self.client.close()
Expand Down