Skip to content

Commit

Permalink
Do not raise if error_code is missing from RestException (mlflow#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiestudies authored and aarondav committed May 8, 2019
1 parent 4eae317 commit cbc9c9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mlflow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def serialize_as_json(self):
class RestException(MlflowException):
"""Exception thrown on non 200-level responses from the REST API"""
def __init__(self, json):
error_code = json['error_code']
error_code = json.get('error_code', INTERNAL_ERROR)
message = error_code
if 'message' in json:
message = "%s: %s" % (error_code, json['message'])
Expand Down
14 changes: 13 additions & 1 deletion tests/utils/test_exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from mlflow.exceptions import ExecutionException
from mlflow.exceptions import ExecutionException, RestException


def test_execution_exception_string_repr():
exc = ExecutionException("Uh oh")
assert str(exc) == "Uh oh"


def test_rest_exception_default_error_code():
exc = RestException({"message": "something important."})
assert "something important." in str(exc)


def test_rest_exception_error_code_is_not_none():
error_string = "something important."
exc = RestException({"message": error_string})
assert "None" not in error_string
assert "None" not in str(exc)

0 comments on commit cbc9c9e

Please sign in to comment.