labd / commercetools-python-sdk

Commercetools Python SDK
https://commercetools-python-sdk.readthedocs.io/en/latest/
MIT License
17 stars 16 forks source link

Error response cannot be parsed #134

Open tleguijt opened 3 years ago

tleguijt commented 3 years ago

Tested version: 14.0.0b12

Problem commercetools SDK raises an Exception (no CommercetoolsError) because it cannot parse an error response from commercetools;

Could not parse error response This is due to a validation error:

{'errors': {0: {'actionIndex': ['Unknown field.'], 'action': ['Unknown field.']}}}

In the following block:

        try:
            obj = ErrorResponseSchema().loads(response.content)
        except ValidationError:
            raise Exception(f"Could not parse error response: {response.content}")

Example response:

b'{"statusCode":400,"message":"A value is required for field \'contract\'.","errors":[{"code":"RequiredField","message":"A value is required for field \'contract\'.","action":{"action":"setCustomField","name":"someCustomField","value":"24e3565c-9135-ec11-a459-6045bd8b7265"},"actionIndex":1,"field":"contract"}]}'