Skip to content

Commit 7d8cd69

Browse files
committed
doc(_api): Give more description to magic numbers
1 parent 2a66b51 commit 7d8cd69

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

openml/_api_calls.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,23 +459,28 @@ def __parse_server_exception(
459459
url: str,
460460
file_elements: FILE_ELEMENTS_TYPE | None,
461461
) -> OpenMLServerError:
462-
# You can find the individual codes that are parsed out of the response here:
463-
# https://github.com/openml/OpenML/blob/develop/openml_OS/views/pages/api_new/v1/xml/pre.php
464-
if response.status_code == 414:
462+
if response.status_code == requests.codes.URI_TOO_LONG:
465463
raise OpenMLServerError(f"URI too long! ({url})")
466464

465+
# OpenML has a sophisticated error system where information about failures is provided,
466+
# in the response body itself.
467+
# First, we need to parse it out.
467468
try:
468469
server_exception = xmltodict.parse(response.text)
469470
except xml.parsers.expat.ExpatError as e:
470471
raise e
471472
except Exception as e:
472-
# OpenML has a sophisticated error system
473-
# where information about failures is provided. try to parse this
473+
# If we failed to parse it out, then something has gone wrong in the body we have sent back
474+
# from the server and there is little extra information we can capture.
474475
raise OpenMLServerError(
475476
f"Unexpected server error when calling {url}. Please contact the developers!\n"
476477
f"Status code: {response.status_code}\n{response.text}",
477478
) from e
478479

480+
# Now we can parse out the specific error codes that we return. These
481+
# are in addition to the typical HTTP error codes, but encode more
482+
# specific informtion. You can find these codes here:
483+
# https://github.com/openml/OpenML/blob/develop/openml_OS/views/pages/api_new/v1/xml/pre.php
479484
server_error = server_exception["oml:error"]
480485
code = int(server_error["oml:code"])
481486
message = server_error["oml:message"]

0 commit comments

Comments
 (0)