Skip to content

Commit

Permalink
Merge pull request #855 from dtaniwaki/fix-status-code
Browse files Browse the repository at this point in the history
Fix status code handling
  • Loading branch information
seldondev authored Sep 13, 2019
2 parents 806e31b + 85d8ed5 commit ec41863
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/seldon_core/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_rest_microservice(user_model):
def handle_invalid_usage(error):
response = jsonify(error.to_dict())
logger.error("%s", error.to_dict())
response.status_code = 400
response.status_code = error.status_code
return response

@app.route("/seldon.json", methods=["GET"])
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_model_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from seldon_core.proto import prediction_pb2
from seldon_core.user_model import SeldonComponent
from seldon_core.utils import seldon_message_to_json, json_to_seldon_message
from seldon_core.flask_utils import SeldonMicroserviceException

from flask import jsonify

Expand Down Expand Up @@ -363,6 +364,21 @@ def test_model_bad_metrics():
assert rv.status_code == 400


def test_model_error_status_code():
class ErrorUserObject():
def predict(self, X, features_names, **kwargs):
raise SeldonMicroserviceException("foo", status_code=403)

user_object = ErrorUserObject()
app = get_rest_microservice(user_object)
client = app.test_client()
uo = UserObject()
rv = client.get('/predict?json={"strData":"my data"}')
j = json.loads(rv.data)
print(j)
assert rv.status_code == 403


def test_model_gets_meta():
user_object = UserObject(ret_meta=True)
app = get_rest_microservice(user_object)
Expand Down

0 comments on commit ec41863

Please sign in to comment.