You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So everything runs fine if the there is no error. But in case of error (e.g. the user inputing the data in the wrong format) the API returns a 200 status code as well accompanied by the string error message as output. This behavior is clear from reading the code. My question is now: how can I make the API return a 500 on error and output the error message?
I tried something like this, but then the 500 was simply included in the output string and it still returned a 200:
returnerror, 500
This happily gives me the string ["some error message", 500] with a 200 status code :)
Any idea how I can achieve this?
Thanks in advance!
The text was updated successfully, but these errors were encountered:
No, unfortunately I haven't found anything... It still still happily returns a 200 with the primitive error message as return string. We have chosen to live with this on the meantime. Makes life and debugging harder...
I have not been able to test it yet, but might test it later.
You could possibly look into using this: from azureml.contrib.services.aml_response import AMLResponse
example:
from azureml.contrib.services.aml_request import AMLRequest, rawhttp
from azureml.contrib.services.aml_response import AMLResponse
from PIL import Image
import json
def init():
print("This is init()")
@rawhttp
def run(request):
print("This is run()")
if request.method == 'GET':
# For this example, just return the URL for GETs.
respBody = str.encode(request.full_path)
return AMLResponse(respBody, 200)
elif request.method == 'POST':
file_bytes = request.files["image"]
image = Image.open(file_bytes).convert('RGB')
# For a real-world solution, you would load the data from reqBody
# and send it to the model. Then return the response.
# For demonstration purposes, this example just returns the size of the image as the response..
return AMLResponse(json.dumps(image.size), 200)
else:
return AMLResponse("bad request", 500)
Hi everybody!
I am following the official tutorials and thus my run function looks like this:
So everything runs fine if the there is no error. But in case of error (e.g. the user inputing the data in the wrong format) the API returns a 200 status code as well accompanied by the string error message as output. This behavior is clear from reading the code. My question is now: how can I make the API return a 500 on error and output the error message?
I tried something like this, but then the 500 was simply included in the output string and it still returned a 200:
This happily gives me the string
["some error message", 500]
with a 200 status code :)Any idea how I can achieve this?
Thanks in advance!
The text was updated successfully, but these errors were encountered: