This message was deleted.
# ask-for-help
s
This message was deleted.
➕ 2
l
hey Axel, would you say your question is related to this one?
a
Hi @Luis Redondo Cañada! Thanks for the follow-up. Yes it is. Here's some clarification: when a specific know internal error occurs, I return a comprehensive JSON response to the client such as:
Copy code
def _error_response(self, message: str) -> Dict[str, str | Dict]:
        """
        Generates an error response with a given message.

        Args:
            message: Error description.

        Returns:
            Error response dictionary.
        """
        self.logger.error(message)
        return {'status': 'Failed', 'error': message, 'waste': {}, 'equipment': {}}
The issue here is that it does not raise and so while the error does show up in the logging, it does not report as an error 500 on the prometheus
/metrics
. Did you managed to achieve a more reasonable solution?
l
no, you've gotten further than me. I just wanted to see if it was related to my question so that we can flag the BentoML folks about its "relevance". cc @Tim Liu
a
Hi @Axel Mendoza see if this helps to return the output along with setting the status code :
Copy code
async def classify(input_features: Feature, ctx: bentoml.Context) -> JSON():
    # Authentication check
    auth_key = ctx.request.headers.get('Authorization')
    if auth_key != API_AUTH_TOKEN:
        ctx.response.status_code = 401  # Unauthorized
        return {"error": "Unauthorized access"}
    
    # Access the model version from the runner
    output = await runner.predict.async_run(input_features)
    if 'error' in output:
        ctx.response.status_code = 406
    return output
In this case output is a json and if it has a key as 'error' then we set the status_code and return the json and same with unauthorized access.
a
Hi @Avil Aneja, this seems awesome! Thanks a lot. I'll try it 🙏