From b6bb2b80cfd3b1e76523c2d64b18de335b32ccdd Mon Sep 17 00:00:00 2001 From: Georg Waltner Date: Wed, 30 Sep 2020 12:53:05 +0200 Subject: [PATCH] Add parameter to allow error printing suppression Allow for `_send` to fail silently without printing the error message. Often it is useful to handle (and print) the error outside the `_send` function. This commit adds a `print_err` argument (defaults to True), so to suppress the error printing one can simply set this to False. --- graphqlclient/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/graphqlclient/client.py b/graphqlclient/client.py index b25de54..f3d6d17 100644 --- a/graphqlclient/client.py +++ b/graphqlclient/client.py @@ -14,7 +14,7 @@ def inject_token(self, token, headername='Authorization'): self.token = token self.headername = headername - def _send(self, query, variables): + def _send(self, query, variables, print_err=True): data = {'query': query, 'variables': variables} headers = {'Accept': 'application/json', @@ -29,6 +29,7 @@ def _send(self, query, variables): response = urllib.request.urlopen(req) return response.read().decode('utf-8') except urllib.error.HTTPError as e: - print((e.read())) - print('') + if print_err is True: + print((e.read())) + print('') raise e