From 7982aa327a19e93593f72233cd6f8397908d318a Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 11 Sep 2019 18:02:30 +0900 Subject: [PATCH] Fix status code handling --- python/seldon_core/wrapper.py | 2 +- python/tests/test_model_microservice.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python/seldon_core/wrapper.py b/python/seldon_core/wrapper.py index 9805203c53..e48a508207 100644 --- a/python/seldon_core/wrapper.py +++ b/python/seldon_core/wrapper.py @@ -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"]) diff --git a/python/tests/test_model_microservice.py b/python/tests/test_model_microservice.py index 42b76f1fde..60bc5792ce 100644 --- a/python/tests/test_model_microservice.py +++ b/python/tests/test_model_microservice.py @@ -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 @@ -365,6 +366,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)