Slackbot
02/02/2024, 9:54 AMLuis Redondo Cañada
02/05/2024, 3:22 PMAxel Mendoza
02/06/2024, 8:25 AMdef _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?Luis Redondo Cañada
02/06/2024, 8:29 AMAvil Aneja
02/06/2024, 10:59 AMasync 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.Axel Mendoza
02/08/2024, 8:33 AM