Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Exceptions raised in predict function of a wrapper class needs to be handled via flask exception handler #625

Closed
klalit opened this issue Jun 8, 2019 · 1 comment · Fixed by #651

Comments

@klalit
Copy link
Contributor

klalit commented Jun 8, 2019

In https://github.com/SeldonIO/seldon-core/blob/master/python/seldon_core/wrapper.py the handler is present for SeldonMicroserviceException but not for user exception. I'm thinking to have a handler created for "Exception" and the function to handle it can be defined in the user model. Please let me know the thoughts or a better way to accomplish the requirement

@klalit
Copy link
Contributor Author

klalit commented Jun 12, 2019

I'm planning to use flask Blueprint so that application developers can integrate in a flexible and cleaner way. Here is the example

Model wrapper

class UserObject(SeldonComponent):

 ** The variable defined for the wrapper.py to consider dusring flask app initialization **
    model_error_handler = flask.Blueprint('error_handlers', __name__)

 ** Register the exception handler **
    @model_error_handler.app_errorhandler(UserCustomException)
    def handleCustomError(error):
        response = jsonify(error.to_dict())
        response.status_code = error.status_code
        return response

    def __init__(self, metrics_ok=True, ret_nparray=False, ret_meta=False):
        pass

    def predict(self, X, features_names, **kwargs):
        raise UserCustomException('Test-Error-Msg',1402,402)
        return X

User exception

class UserCustomException(Exception):
    status_code = 404

    def __init__(self, message, application_error_code,http_status_code):
        Exception.__init__(self)
        self.message = message
        if http_status_code is not None:
            self.status_code = http_status_code
        self.application_error_code = application_error_code

    def to_dict(self):
        rv = {"status": {"status": self.status_code, "message": self.message,
                         "app_code": self.application_error_code}}
        return rv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant