From 830cf82230e084b523e167cffe5450a42f49ebea Mon Sep 17 00:00:00 2001 From: TwoPerCent Date: Thu, 18 Apr 2024 03:31:18 -0400 Subject: [PATCH] api msg handling --- stability_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stability_api.py b/stability_api.py index ae36e98..6ee1985 100644 --- a/stability_api.py +++ b/stability_api.py @@ -108,7 +108,12 @@ class StabilityBase: else: error_info = response.json() if error_info.get("name") == "unauthorized": - raise Exception(f"Stability API Error: Unauthorized.\n\nUse your Stability AI API key by:\n1. Setting the SAI_API_KEY environment variable to your API key\n3. Placing inside sai_platform_key.txt\n4. Passing the API key as an argument to the function with the key 'api_key_override'") + raise Exception("Stability API Error: Unauthorized.\n\nUse your Stability AI API key by:\n1. Setting the SAI_API_KEY environment variable to your API key\n3. Placing inside sai_platform_key.txt\n4. Passing the API key as an argument to the function with the key 'api_key_override'") + if error_info.get("name") == "payment_required": + raise Exception("Stability API Error: Not enough credits.\n\nPlease ensure your SAI API account has enough credits to complete this action.") + if error_info.get("name") == "bad_request": + errors = '\n'.join(error_info.get('errors')) + raise Exception(f"Stability API Error: Bad request.\n\n{errors}") else: raise Exception(f"Stability API Error: {error_info}")