From 8be714b1699c6ef160a7a790f089a0a5056e856e Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 21 Jul 2020 15:16:37 +1000 Subject: [PATCH] chore sdk Add Examples for each of the exceptions --- examples/exceptions/api_exception.py | 17 ++++++++++++ .../invalid_credentials_exception.py | 15 +++++++++++ examples/exceptions/validation_exception.py | 27 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 examples/exceptions/api_exception.py create mode 100644 examples/exceptions/invalid_credentials_exception.py create mode 100644 examples/exceptions/validation_exception.py diff --git a/examples/exceptions/api_exception.py b/examples/exceptions/api_exception.py new file mode 100644 index 0000000..780cda6 --- /dev/null +++ b/examples/exceptions/api_exception.py @@ -0,0 +1,17 @@ +import os + +from staxapp.config import Config +from staxapp.openapi import StaxClient +from staxapp.exceptions import ApiException + +Config.access_key = os.getenv("STAX_ACCESS_KEY") +Config.secret_key = os.getenv("STAX_SECRET_KEY") + +# Read all workload catalogue items within your Stax Organisation +workloads = StaxClient("workloads") +try: + response = workloads.ReadCatalogueItems() +except ApiException as e: + print(e) + if e.status_code == 404: + print("No Catalogues exist") diff --git a/examples/exceptions/invalid_credentials_exception.py b/examples/exceptions/invalid_credentials_exception.py new file mode 100644 index 0000000..28d89eb --- /dev/null +++ b/examples/exceptions/invalid_credentials_exception.py @@ -0,0 +1,15 @@ +import os + +from staxapp.config import Config +from staxapp.openapi import StaxClient +from staxapp.exceptions import InvalidCredentialsException + +Config.access_key = os.getenv("STAX_ACCESS_KEY") +Config.secret_key = os.getenv("STAX_SECRET_KEY") + +# Read all workload catalogue items within your Stax Organisation +try: + workloads = StaxClient("workloads") +except InvalidCredentialsException as e: + print(e) + # Try other credentials diff --git a/examples/exceptions/validation_exception.py b/examples/exceptions/validation_exception.py new file mode 100644 index 0000000..0a2420a --- /dev/null +++ b/examples/exceptions/validation_exception.py @@ -0,0 +1,27 @@ +import os + +from staxapp.config import Config +from staxapp.openapi import StaxClient +from staxapp.exceptions import ValidationException + +Config.access_key = os.getenv("STAX_ACCESS_KEY") +Config.secret_key = os.getenv("STAX_SECRET_KEY") + +# The user's first name +first_name = +# The user's second name +last_name = +# The email for the user +user_email = + +try: + # Create a Stax User + teams = StaxClient("teams") + response = teams.CreateUser( + FirstName = first_name, + LastName = last_name, + Email = user_email + ) +except InvalidCredentialsException as e: + print(e) + # Try adding a missing field or validating the params