API Exceptions
API Client Exceptions¶
APIError
¶
Bases: CRIPTException
Definition¶
This is a generic error made to display API errors to the user to troubleshoot.
Troubleshooting¶
Please keep in mind that the CRIPT Python SDK turns the Project node into a giant JSON and sends that to the API to be processed. If there are any errors while processing the giant JSON generated by the CRIPT Python SDK, then the API will return an error about the http request and the JSON sent to it.
The best way to trouble shoot this is to figure out what the API error means and figure out where in the Python SDK this error occurred and what could be the reason under the hood.
Steps to try:¶
- What does the API error mean?
- Is the error something you can easily fix by maybe renaming a node?
- Does the
http_method
look reasonable? - Does the
URL
that the data was sent to look reasonable?
- Is there a problem within the JSON?
- Is the problem within how the SDK is converting nodes from and to JSON (serialization and deserialization)?
Source code in src/cript/api/exceptions.py
CRIPTAPIRequiredError
¶
Bases: CRIPTException
Definition¶
Exception to be raised when the API object is requested, but no cript.API object exists yet.
Also make sure to use it in a context manager with cript.API as api:
or manually call
connect
and disconnect
.
The CRIPT Python SDK relies on a cript.API object for creation, validation, and modification of nodes. The cript.API object may be explicitly called by the user to perform operations to the API, or implicitly called by the Python SDK under the hood to perform some sort of validation.
Troubleshooting¶
To fix this error please instantiate an api object
import cript
my_host = "https://api.criptapp.org/"
my_token = "123456" # To use your token securely, please consider using environment variables
my_api = cript.API(host=my_host, token=my_token)
my_api.connect()
# Your code
my_api.disconnect()
Source code in src/cript/api/exceptions.py
CRIPTAPISaveError
¶
Bases: CRIPTException
Definition¶
CRIPTAPISaveError is raised when the API responds with a http status code that is anything other than 200. The status code and API response is shown to the user to help them debug the issue.
Troubleshooting¶
This error is more of a case by case basis, but the best way to approach it to understand that the CRIPT Python SDK sent an HTTP POST request with a giant JSON in the request body to the CRIPT API. The API then read that request, and it responded with some sort of error either to the that JSON or how the request was sent.
Source code in src/cript/api/exceptions.py
CRIPTConnectionError
¶
Bases: CRIPTException
Definition¶
Raised when the cript.API object cannot connect to CRIPT with the given host and token
Troubleshooting¶
The best way to fix this error is to check that your host and token are written and used correctly within the cript.API object. This error could also be shown if the API is unresponsive and the cript.API object just cannot successfully connect to it.
Source code in src/cript/api/exceptions.py
CRIPTDuplicateNameError
¶
Bases: CRIPTAPISaveError
Exception raised when attempting to save a node with a name that already exists in CRIPT.
This exception class extends CRIPTAPISaveError
and is used to handle errors
that occur when a node's name duplicates an existing node's name in the CRIPT database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_response |
dict
|
The response returned from the API that contains the error details. |
required |
json_data |
str
|
The JSON data of the node that caused the duplication error. |
required |
parent_cript_save_error |
CRIPTAPISaveError
|
The original |
required |
Make |
|
required | |
If |
|
required |
Source code in src/cript/api/exceptions.py
FileDownloadError
¶
Bases: CRIPTException
Definition¶
This error is raised when the API wants to download a file from an AWS S3 URL
via the cript.API.download_file()
method, but the status is something other than 200.
Source code in src/cript/api/exceptions.py
InvalidHostError
¶
Bases: CRIPTException
Definition¶
Exception is raised when the host given to the API is invalid
Troubleshooting¶
This is a simple error to fix, simply put http://
or preferably https://
in front of your domain
when passing in the host to the cript.API class such as https://api.criptapp.org/
Currently, the only web protocol that is supported with the CRIPT Python SDK is HTTP
.
Example¶
import cript
my_valid_host = "https://api.criptapp.org/"
my_token = "123456" # To use your token securely, please consider using environment variables
my_api = cript.API(host=my_valid_host, token=my_token)
Warnings
Please consider always using HTTPS
as that is a secure protocol and avoid using HTTP
as it is insecure.
The CRIPT Python SDK will give a warning in the terminal when it detects a host with HTTP
Source code in src/cript/api/exceptions.py
InvalidVocabulary
¶
Bases: CRIPTException
Raised when the CRIPT controlled vocabulary is invalid
Source code in src/cript/api/exceptions.py
InvalidVocabularyCategory
¶
Bases: CRIPTException
Raised when the CRIPT controlled vocabulary category is unknown and gives the user a list of all valid vocabulary categories