Skip to content
Open
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
17 changes: 17 additions & 0 deletions examples/exceptions/api_exception.py
Original file line number Diff line number Diff line change
@@ -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")
15 changes: 15 additions & 0 deletions examples/exceptions/invalid_credentials_exception.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions examples/exceptions/validation_exception.py
Original file line number Diff line number Diff line change
@@ -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 = <User's first Name>
# The user's second name
last_name = <User's last Name>
# The email for the user
user_email = <User's 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