Open xuweidongkobe opened 1 year ago
You can have a custom exception.
You can have a custom exception.
This error occurred before entered my service script, and I cannot make up for a custom exception.@arnavmehta7 Can you tell me how to make a useful custom exception? Thank you.
@xuweidongkobe Are you setting the headers then set to Application/json? Any snippets?
@xuweidongkobe Are you setting the headers then set to Application/json? Any snippets?
In the code, I use the default head and input data format. In postman test, I am set input data in Application/json format.@arnavmehta7
@xuweidongkobe Here is an example where we pass a list in the request body and the handler is reading the list. You can use a similar logic to check if its a valid json and show appropriate error message https://github.com/pytorch/serve/blob/master/examples/image_classifier/near_real_time_video/near_real_time_video_handler.py#L20-L21
When the request body does not in the valid JSON format, an error was occurred before entering the preprocess function. @agunapal
What if we consider using the following code snippet?
import json
try:
input_data = json.loads(input_json)
# Process input_data here
except json.JSONDecodeError as e:
return {
"code": 500,
"type": "InternalServerException",
"message": "Worker died."
}
🚀 The feature
Given a custom service that expects JSON as input, If the input is invalid JSON such as { "image": "I missed a quote} it will return { "code": 500, "type": "InternalServerException", "message": "Worker died." } and reload model. Is something can do to verify the accuracy of input to avoid such direct returns and model reload when it cannot be modified input?
Motivation, pitch
Is something can do to verify the accuracy of input to avoid such direct returns and model reload when it cannot be modified input?
Alternatives
No response
Additional context
No response