|
1 | 1 | """Python client for the Yeti API."""
|
2 | 2 |
|
3 |
| -import requests |
4 |
| -import requests_toolbelt.multipart.encoder as encoder |
5 |
| - |
6 | 3 | import json
|
7 | 4 | from typing import Any, Sequence
|
8 | 5 |
|
| 6 | +import yeti.errors as errors |
| 7 | +import requests |
| 8 | +import requests_toolbelt.multipart.encoder as encoder |
9 | 9 |
|
10 | 10 | TYPE_TO_ENDPOINT = {
|
11 | 11 | "indicator": "/api/v2/indicators",
|
@@ -73,14 +73,19 @@ def do_request(
|
73 | 73 | if body:
|
74 | 74 | request_kwargs["body"] = body
|
75 | 75 |
|
76 |
| - if method == "POST": |
77 |
| - response = self.client.post(url, **request_kwargs) |
78 |
| - elif method == "PATCH": |
79 |
| - response = self.client.patch(url, **request_kwargs) |
80 |
| - elif method == "GET": |
81 |
| - response = self.client.get(url, **request_kwargs) |
82 |
| - else: |
83 |
| - raise ValueError(f"Unsupported method: {method}") |
| 76 | + try: |
| 77 | + if method == "POST": |
| 78 | + response = self.client.post(url, **request_kwargs) |
| 79 | + elif method == "PATCH": |
| 80 | + response = self.client.patch(url, **request_kwargs) |
| 81 | + elif method == "GET": |
| 82 | + response = self.client.get(url, **request_kwargs) |
| 83 | + else: |
| 84 | + raise ValueError(f"Unsupported method: {method}") |
| 85 | + response.raise_for_status() |
| 86 | + except requests.exceptions.HTTPError as e: |
| 87 | + raise errors.YetiApiError(e.response.status_code, e.response.text) |
| 88 | + |
84 | 89 | return response.bytes
|
85 | 90 |
|
86 | 91 | def auth_api_key(self, apikey: str) -> None:
|
|
0 commit comments