Skip to content

Commit 80f3f5f

Browse files
authored
chore: Improve error message if there is no organization with required name (influxdata#425)
1 parent 20c867d commit 80f3f5f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.28.0 [unreleased]
22

3+
### Bug Fixes
4+
1. [#425](https://github.com/influxdata/influxdb-client-python/pull/425): Improve error message if there is no `organization` with required `name`
5+
36
## 1.27.0 [2022-03-18]
47

58
### Features

influxdb_client/client/util/helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def get_org_query_param(org, client, required_id=False):
3939
"to determine their ID. Are you using token with sufficient permission?"
4040
raise InfluxDBError(response=None, message=message)
4141
return organizations[0].id
42-
except ApiException:
43-
return None
42+
except ApiException as e:
43+
if e.status == 404:
44+
from influxdb_client.client.exceptions import InfluxDBError
45+
message = f"The client cannot find organization with name: '{_org}' " \
46+
"to determine their ID."
47+
raise InfluxDBError(response=None, message=message)
48+
raise e
4449

4550
return _org

tests/test_Helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def test_required_id(self):
3131
self.assertEqual(self.my_organization.id, org)
3232

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

3738
def test_both_none(self):
3839
self.client.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy