Skip to content

Commit 9815fd3

Browse files
authored
Merge pull request #352 from C-Accel-CRIPT/refactor-apierror
* clean up `APIError` so it is uniform everywhere and clean * removed unnecessary code since it is being used uniformly everywhere
2 parents f0088ef + 97a6363 commit 9815fd3

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/cript/api/exceptions.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
2-
from typing import List, Optional, Set
2+
from typing import List, Set
3+
4+
from beartype import beartype
35

46
from cript.exceptions import CRIPTException
57

@@ -215,10 +217,11 @@ class APIError(CRIPTException):
215217
api_error: str = ""
216218

217219
# having the URL that the API gave an error for helps in debugging
218-
api_url: Optional[str] = None
219-
http_method: Optional[str] = None
220+
api_url: str = ""
221+
http_method: str = ""
220222

221-
def __init__(self, api_error: str, http_method: Optional[str] = None, api_url: Optional[str] = None) -> None:
223+
@beartype
224+
def __init__(self, api_error: str, http_method: str, api_url: str) -> None:
222225
self.api_error = api_error
223226

224227
self.api_url = api_url
@@ -228,14 +231,7 @@ def __init__(self, api_error: str, http_method: Optional[str] = None, api_url: O
228231
self.http_method = http_method
229232

230233
def __str__(self) -> str:
231-
# TODO refactor all of SDK using this error to be used the same to avoid this logic and Optional attributes
232-
# this logic currently exists to make previous SDK work
233-
234-
# if you have the URL then display it, otherwise just show the error message
235-
if self.api_url and self.http_method:
236-
return f"CRIPT Python SDK sent HTTP `{self.http_method.upper()}` request to URL: `{self.api_url}` and API responded with {self.api_error}"
237-
else:
238-
return f"The API responded with: {self.api_error}"
234+
return f"CRIPT Python SDK sent HTTP `{self.http_method.upper()}` request to URL: `{self.api_url}` and API responded with {self.api_error}"
239235

240236

241237
class FileDownloadError(CRIPTException):

0 commit comments

Comments
 (0)