Skip to content

Commit

Permalink
chore: look for "detail" instead of "message" in API responses
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Léobal <[email protected]>
  • Loading branch information
oleobal committed Aug 2, 2023
1 parent 7a2a7f0 commit 4aab0de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions substra/sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, msg, status_code):
def from_request_exception(cls, request_exception):
msg = None
try:
msg = request_exception.response.json()["message"]
msg = request_exception.response.json()["detail"]
msg = f"{request_exception}: {msg}"
except Exception:
msg = str(request_exception)
Expand Down Expand Up @@ -63,7 +63,7 @@ def from_request_exception(cls, request_exception):

get_method = getattr(error, "get", None)
if callable(get_method):
msg = get_method("message", str(error))
msg = get_method("detail", str(error))
else:
msg = str(error)

Expand Down Expand Up @@ -91,7 +91,7 @@ def from_request_exception(cls, request_exception):
r = request_exception.response.json()

try:
key = r["key"] if "key" in r else r["message"].get("key")
key = r["key"] if "key" in r else r["detail"].get("key")
except (AttributeError, KeyError):
# XXX this is the case when doing a POST query to update the
# data manager for instance
Expand Down Expand Up @@ -197,7 +197,7 @@ class KeyAlreadyExistsError(Exception):


class _TaskAssetError(Exception):
"""Base eception class for task asset error"""
"""Base exception class for task asset error"""

def __init__(self, *, compute_task_key: str, identifier: str, message: str):
self.compute_task_key = compute_task_key
Expand Down
8 changes: 4 additions & 4 deletions tests/sdk/test_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def test_post_success(mocker, config):
@pytest.mark.parametrize(
"status_code, http_response, sdk_exception",
[
(400, {"message": "Invalid Request"}, exceptions.InvalidRequest),
(401, {"message": "Invalid username/password"}, exceptions.AuthenticationError),
(403, {"message": "Unauthorized"}, exceptions.AuthorizationError),
(404, {"message": "Not Found"}, exceptions.NotFound),
(400, {"detail": "Invalid Request"}, exceptions.InvalidRequest),
(401, {"detail": "Invalid username/password"}, exceptions.AuthenticationError),
(403, {"detail": "Unauthorized"}, exceptions.AuthorizationError),
(404, {"detail": "Not Found"}, exceptions.NotFound),
(408, {"key": "a-key"}, exceptions.RequestTimeout),
(408, {}, exceptions.RequestTimeout),
(500, "CRASH", exceptions.InternalServerError),
Expand Down

0 comments on commit 4aab0de

Please sign in to comment.