Skip to content

Commit 26ea6aa

Browse files
committed
Throw detailed exception when error message could not be parsed
In some cases the schema does not match the response. In this case it's not possible anymore to see what the original error was. This is a quick fix to at least have some more sense of why commercetools responded with an error.
1 parent 6b3c7e5 commit 26ea6aa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/commercetools/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import warnings
44

55
import requests
6+
from marshmallow.exceptions import ValidationError
67

78
from commercetools.helpers import _concurrent_retry
89

@@ -102,7 +103,10 @@ def _process_error(self, response: requests.Response) -> None:
102103
# FIXME: The error response defined in the RAML should be used
103104
from commercetools.platform.models._schemas.error import ErrorResponseSchema
104105

105-
obj = ErrorResponseSchema().loads(response.content)
106+
try:
107+
obj = ErrorResponseSchema().loads(response.content)
108+
except ValidationError:
109+
raise Exception(f"Could not parse error response: {response.content}")
106110

107111
# We'll fetch the 'raw' errors from the response because some of the
108112
# attributes are not included in the schemas.

0 commit comments

Comments
 (0)