diff --git a/databricks/sdk/errors/parser.py b/databricks/sdk/errors/parser.py index 404a597ba..5d0d65033 100644 --- a/databricks/sdk/errors/parser.py +++ b/databricks/sdk/errors/parser.py @@ -13,6 +13,19 @@ from .private_link import (_get_private_link_validation_error, _is_private_link_redirect) +class _CatchAllErrorDeserializer: + """ + A catch-all deserializer that sets the entire response body as the error message. + """ + + def deserialize_error(self, response: requests.Response, content: bytes) -> dict: + logging.warning('Unable to parse error with specific deserializers, using catch-all deserializer.') + return { + 'message': content.decode('utf-8', errors='replace'), + 'status_code': response.status_code, + 'url': response.url + } + # A list of _ErrorDeserializers that are tried in order to parse an API error from a response body. Most errors should # be parsable by the _StandardErrorDeserializer, but additional parsers can be added here for specific error formats. # The order of the parsers is not important, as the set of errors that can be parsed by each parser should be disjoint. @@ -21,6 +34,7 @@ _StandardErrorDeserializer(), _StringErrorDeserializer(), _HtmlErrorDeserializer(), + _CatchAllErrorDeserializer(), ] # A list of _ErrorCustomizers that are applied to the error arguments after they are parsed. Customizers can modify the