Skip to content

Commit d8e57f6

Browse files
Merge pull request #9 from MislavReversingLabs/main
Add error handling section
2 parents 66a6c31 + bfe4321 commit d8e57f6

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

A1000/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,34 @@ a1000_obj = A1000(
6363

6464
Now that you have an API object, you can proceed to call any of the available methods that the object contains.
6565
To see specific usage examples or recommended scenarios for certain API-s, check the provided **notebooks**
66-
(**ipynb** files).
66+
(**ipynb** files).
67+
68+
69+
## Advanced
70+
### Error handling
71+
To understand this section better, **learn about creating API requests first** by reading the notebooks in the A1000 folder.
72+
Each module raises corresponding custom exceptions according to the error status code returned in the response.
73+
Custom exception classes that correspond to error status codes also carry the original response object in its entirety.
74+
To learn how to fetch and use the response object out of the exception object, see the following example.
75+
76+
```python
77+
from ReversingLabs.SDK.a1000 import A1000
78+
79+
80+
a1000_obj = A1000(
81+
host="url_of_a1000_instance",
82+
token="your_actual_token",
83+
verify=True
84+
)
85+
86+
try:
87+
resp = a1000_obj.get_classification_v3(
88+
sample_hash="cf23df2207d99a74fbe169e3eba035e633b65d94",
89+
av_scanners=True
90+
)
91+
except Exception as e:
92+
if hasattr(e, "response_object"):
93+
print(e.response_object.content)
94+
else:
95+
raise
96+
```

TitaniumCloud/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,30 @@ file_reputation = FileReputation(
6060
Now that you have an API object, you can proceed to call any of the available methods that the object contains.
6161
To see specific usage examples or recommended scenarios for certain API-s, check the provided **notebooks**
6262
(**ipynb** files).
63+
64+
65+
## Advanced
66+
### Error handling
67+
To understand this section better, **learn about creating API requests first** by reading the notebooks in the TitaniumCloud folder.
68+
Each module raises corresponding custom exceptions according to the error status code returned in the response.
69+
Custom exception classes that correspond to error status codes also carry the original response object in its entirety.
70+
To learn how to fetch and use the response object out of the exception object, see the following example.
71+
72+
```python
73+
from ReversingLabs.SDK.ticloud import FileReputation
74+
75+
76+
file_rep = FileReputation(
77+
host="https://data.reversinglabs.com",
78+
username="u/username",
79+
password="password"
80+
)
81+
82+
try:
83+
resp = file_rep.get_file_reputation(hash_input="cf23df2207d99a74fbe169e3eba035e633b65d94")
84+
except Exception as e:
85+
if hasattr(e, "response_object"):
86+
print(e.response_object.content)
87+
else:
88+
raise
89+
```

0 commit comments

Comments
 (0)