From 2437581d3b8fcba932254cd81a78ea61ac7eec1a Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Tue, 10 Sep 2024 13:19:11 +0200 Subject: [PATCH 1/2] Fix SCIM error handling --- databricks/sdk/errors/parser.py | 5 +++-- tests/test_errors.py | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/databricks/sdk/errors/parser.py b/databricks/sdk/errors/parser.py index e2feb99d..3d15f167 100644 --- a/databricks/sdk/errors/parser.py +++ b/databricks/sdk/errors/parser.py @@ -60,8 +60,9 @@ def parse_error(self, response: requests.Response, response_body: bytes) -> Opti if detail: # Handle SCIM error message details # @see https://tools.ietf.org/html/rfc7644#section-3.7.3 - error_args[ - 'message'] = f"{scim_type} {error_args.get('message', 'SCIM API Internal Error')}".strip(" ") + if detail == "null": + detail = "SCIM API Internal Error" + error_args['message'] = f"{scim_type} {detail}".strip(" ") error_args['error_code'] = f"SCIM_{status}" return error_args diff --git a/tests/test_errors.py b/tests/test_errors.py index 1dfcfaf2..4d676b18 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -109,7 +109,14 @@ def make_private_link_response() -> requests.Response: 'Please report this issue with the following debugging information to the SDK issue tracker at ' 'https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/service\n' '< 400 Bad Request\n' - '< this is not a real response```')), ]) + '< this is not a real response```')), + [fake_response('GET', 404, json.dumps({ + 'detail': 'Group with id 1234 is not found', + 'status': '404', + 'schemas': [ + 'urn:ietf:params:scim:api:messages:2.0:Error' + ] + })), errors.NotFound, 'None Group with id 1234 is not found']]) def test_get_api_error(response, expected_error, expected_message): with pytest.raises(errors.DatabricksError) as e: raise errors.get_api_error(response) From 03c52b8896fb1089c8ed75218a98976a977650a2 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Tue, 10 Sep 2024 13:23:07 +0200 Subject: [PATCH 2/2] fmt --- tests/test_errors.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_errors.py b/tests/test_errors.py index 4d676b18..2e19ec89 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -110,13 +110,15 @@ def make_private_link_response() -> requests.Response: 'https://github.com/databricks/databricks-sdk-go/issues. Request log:```GET /api/2.0/service\n' '< 400 Bad Request\n' '< this is not a real response```')), - [fake_response('GET', 404, json.dumps({ - 'detail': 'Group with id 1234 is not found', - 'status': '404', - 'schemas': [ - 'urn:ietf:params:scim:api:messages:2.0:Error' - ] - })), errors.NotFound, 'None Group with id 1234 is not found']]) + [ + fake_response( + 'GET', 404, + json.dumps({ + 'detail': 'Group with id 1234 is not found', + 'status': '404', + 'schemas': ['urn:ietf:params:scim:api:messages:2.0:Error'] + })), errors.NotFound, 'None Group with id 1234 is not found' + ]]) def test_get_api_error(response, expected_error, expected_message): with pytest.raises(errors.DatabricksError) as e: raise errors.get_api_error(response)