Skip to content

Commit 094addf

Browse files
committed
Add catch all error deserializer
1 parent bc6367b commit 094addf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

databricks/sdk/errors/parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
from .private_link import (_get_private_link_validation_error,
1414
_is_private_link_redirect)
1515

16+
class _CatchAllErrorDeserializer:
17+
"""
18+
A catch-all deserializer that sets the entire response body as the error message.
19+
"""
20+
21+
def deserialize_error(self, response: requests.Response, content: bytes) -> dict:
22+
logging.warning('Unable to parse error with specific deserializers, using catch-all deserializer.')
23+
return {
24+
'message': content.decode('utf-8', errors='replace'),
25+
'status_code': response.status_code,
26+
'url': response.url
27+
}
28+
1629
# A list of _ErrorDeserializers that are tried in order to parse an API error from a response body. Most errors should
1730
# be parsable by the _StandardErrorDeserializer, but additional parsers can be added here for specific error formats.
1831
# 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 @@
2134
_StandardErrorDeserializer(),
2235
_StringErrorDeserializer(),
2336
_HtmlErrorDeserializer(),
37+
_CatchAllErrorDeserializer(),
2438
]
2539

2640
# A list of _ErrorCustomizers that are applied to the error arguments after they are parsed. Customizers can modify the

0 commit comments

Comments
 (0)