Skip to content

Commit

Permalink
Merge pull request #9 from MislavReversingLabs/main
Browse files Browse the repository at this point in the history
Add error handling section
  • Loading branch information
MislavReversingLabs authored Apr 2, 2024
2 parents 66a6c31 + bfe4321 commit d8e57f6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
32 changes: 31 additions & 1 deletion A1000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,34 @@ a1000_obj = A1000(

Now that you have an API object, you can proceed to call any of the available methods that the object contains.
To see specific usage examples or recommended scenarios for certain API-s, check the provided **notebooks**
(**ipynb** files).
(**ipynb** files).


## Advanced
### Error handling
To understand this section better, **learn about creating API requests first** by reading the notebooks in the A1000 folder.
Each module raises corresponding custom exceptions according to the error status code returned in the response.
Custom exception classes that correspond to error status codes also carry the original response object in its entirety.
To learn how to fetch and use the response object out of the exception object, see the following example.

```python
from ReversingLabs.SDK.a1000 import A1000


a1000_obj = A1000(
host="url_of_a1000_instance",
token="your_actual_token",
verify=True
)

try:
resp = a1000_obj.get_classification_v3(
sample_hash="cf23df2207d99a74fbe169e3eba035e633b65d94",
av_scanners=True
)
except Exception as e:
if hasattr(e, "response_object"):
print(e.response_object.content)
else:
raise
```
27 changes: 27 additions & 0 deletions TitaniumCloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,30 @@ file_reputation = FileReputation(
Now that you have an API object, you can proceed to call any of the available methods that the object contains.
To see specific usage examples or recommended scenarios for certain API-s, check the provided **notebooks**
(**ipynb** files).


## Advanced
### Error handling
To understand this section better, **learn about creating API requests first** by reading the notebooks in the TitaniumCloud folder.
Each module raises corresponding custom exceptions according to the error status code returned in the response.
Custom exception classes that correspond to error status codes also carry the original response object in its entirety.
To learn how to fetch and use the response object out of the exception object, see the following example.

```python
from ReversingLabs.SDK.ticloud import FileReputation


file_rep = FileReputation(
host="https://data.reversinglabs.com",
username="u/username",
password="password"
)

try:
resp = file_rep.get_file_reputation(hash_input="cf23df2207d99a74fbe169e3eba035e633b65d94")
except Exception as e:
if hasattr(e, "response_object"):
print(e.response_object.content)
else:
raise
```

0 comments on commit d8e57f6

Please sign in to comment.