From 9e410415d12c3bee463201c1fe5170a7a3bdcc80 Mon Sep 17 00:00:00 2001
From: Chris Tran <chris.tran@agilebits.com>
Date: Wed, 8 Jan 2025 12:38:53 -0600
Subject: [PATCH] feat: remove PassageError error message prefixes

---
 passageidentity/auth.py   |  3 +--
 passageidentity/errors.py |  7 +++----
 passageidentity/user.py   | 30 ++++++++++--------------------
 tests/errors_test.py      | 12 ------------
 4 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/passageidentity/auth.py b/passageidentity/auth.py
index 365fb8b..5f6707f 100644
--- a/passageidentity/auth.py
+++ b/passageidentity/auth.py
@@ -94,5 +94,4 @@ def create_magic_link(self, args: MagicLinkArgs, options: MagicLinkOptions | Non
                 _headers=self.request_headers,
             ).magic_link
         except ApiException as e:
-            msg = "Could not create a magic link for this app"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
diff --git a/passageidentity/errors.py b/passageidentity/errors.py
index 217d5df..6921bf9 100644
--- a/passageidentity/errors.py
+++ b/passageidentity/errors.py
@@ -20,19 +20,18 @@ def __str__(self) -> str:
         return self.message
 
     @classmethod
-    def from_response_error(cls, response_error: ApiException, message: str | None = None) -> PassageError:
+    def from_response_error(cls, response_error: ApiException) -> PassageError:
         """Initialize the error with a response body and optional message."""
         if response_error.data is not None:
             data_dict = response_error.data.to_dict()
             error_code = data_dict.get("code")
             error_msg = data_dict.get("error")
-            msg = ": ".join(filter(None, [message, error_msg]))
         else:
             error_code = None
-            msg = str(response_error.body)
+            error_msg = str(response_error.body)
 
         psg_error = cls()
-        psg_error.message = msg
+        psg_error.message = error_msg
         psg_error.status_code = response_error.status
         psg_error.error_code = error_code
 
diff --git a/passageidentity/user.py b/passageidentity/user.py
index 0f5b11a..cf7d658 100644
--- a/passageidentity/user.py
+++ b/passageidentity/user.py
@@ -43,8 +43,7 @@ def get(self, user_id: str) -> PassageUser:
         try:
             return self.users_api.get_user(self.app_id, user_id, _headers=self.request_headers).user
         except ApiException as e:
-            msg = "Could not fetch user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def get_by_identifier(self, identifier: str) -> PassageUser:
         """Get a user's object using their user identifier."""
@@ -60,8 +59,7 @@ def get_by_identifier(self, identifier: str) -> PassageUser:
                 _headers=self.request_headers,
             ).users
         except ApiException as e:
-            msg = "Could not fetch user by identifier"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
         if len(users) == 0:
             raise PassageError.from_response_error(
@@ -79,8 +77,7 @@ def activate(self, user_id: str) -> PassageUser:
         try:
             return self.users_api.activate_user(self.app_id, user_id, _headers=self.request_headers).user
         except ApiException as e:
-            msg = "Could not activate user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def deactivate(self, user_id: str) -> PassageUser:
         """Deactivate a user using their user ID."""
@@ -91,8 +88,7 @@ def deactivate(self, user_id: str) -> PassageUser:
         try:
             return self.users_api.deactivate_user(self.app_id, user_id, _headers=self.request_headers).user
         except ApiException as e:
-            msg = "Could not deactivate user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def update(self, user_id: str, options: UpdateUserArgs) -> PassageUser:
         """Update a user."""
@@ -103,8 +99,7 @@ def update(self, user_id: str, options: UpdateUserArgs) -> PassageUser:
         try:
             return self.users_api.update_user(self.app_id, user_id, options, _headers=self.request_headers).user
         except ApiException as e:
-            msg = "Could not update user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def create(self, args: CreateUserArgs) -> PassageUser:
         """Create a user."""
@@ -115,8 +110,7 @@ def create(self, args: CreateUserArgs) -> PassageUser:
         try:
             return self.users_api.create_user(self.app_id, args, _headers=self.request_headers).user
         except ApiException as e:
-            msg = "Could not create user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def delete(self, user_id: str) -> None:
         """Delete a user using their user ID."""
@@ -127,8 +121,7 @@ def delete(self, user_id: str) -> None:
         try:
             self.users_api.delete_user(self.app_id, user_id, _headers=self.request_headers)
         except ApiException as e:
-            msg = "Could not delete user"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def list_devices(self, user_id: str) -> list[WebAuthnDevices]:
         """Get a user's devices using their user ID."""
@@ -139,8 +132,7 @@ def list_devices(self, user_id: str) -> list[WebAuthnDevices]:
         try:
             return self.user_devices_api.list_user_devices(self.app_id, user_id, _headers=self.request_headers).devices
         except ApiException as e:
-            msg = "Could not fetch user's devices"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def revoke_device(self, user_id: str, device_id: str) -> None:
         """Revoke a user's device using their user ID and the device ID."""
@@ -155,8 +147,7 @@ def revoke_device(self, user_id: str, device_id: str) -> None:
         try:
             self.user_devices_api.delete_user_devices(self.app_id, user_id, device_id, _headers=self.request_headers)
         except ApiException as e:
-            msg = "Could not revoke user's device"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
 
     def revoke_refresh_tokens(self, user_id: str) -> None:
         """Revokes all of a user's Refresh Tokens using their User ID."""
@@ -167,5 +158,4 @@ def revoke_refresh_tokens(self, user_id: str) -> None:
         try:
             self.tokens_api.revoke_user_refresh_tokens(self.app_id, user_id, _headers=self.request_headers)
         except ApiException as e:
-            msg = "Could not revoke user's refresh tokens"
-            raise PassageError.from_response_error(e, msg) from e
+            raise PassageError.from_response_error(e) from e
diff --git a/tests/errors_test.py b/tests/errors_test.py
index 6f03991..5e552e9 100644
--- a/tests/errors_test.py
+++ b/tests/errors_test.py
@@ -18,18 +18,6 @@ def test_from_response_error() -> None:
         data=Model400Error(code="invalid_request", error="some error"),
     )
 
-    error = PassageError.from_response_error(response_error, "some message")
-    assert error.message == "some message: some error"
-    assert error.status_code == 400
-    assert error.error_code == "invalid_request"
-
-
-def test_from_response_error_without_message() -> None:
-    response_error = MockApiException(
-        status=400,
-        data=Model400Error(code="invalid_request", error="some error"),
-    )
-
     error = PassageError.from_response_error(response_error)
     assert error.message == "some error"
     assert error.status_code == 400