Skip to content

Commit

Permalink
Add catch all error deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
dsculptor committed Nov 25, 2024
1 parent bc6367b commit 094addf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions databricks/sdk/errors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 094addf

Please sign in to comment.