Closed Sekhar0799 closed 11 months ago
In this solution, we address the issue where the API was responding with a 500 Internal Server Error when called with improper request parameters for file input. The goal is to provide a more developer-friendly experience by returning a 400 Bad Request status code along with a meaningful error message when the request contains invalid file input.
We use a try
and except
block to capture any exceptions that may occur during the execution of the run
function. These exceptions can include issues related to improper file input.
In the except
block, we handle the exception by returning a JSON response with a 400 status code (Bad Request). The response includes an error message that combines the string "Improper request" with the exception message (if available). This message helps developers understand that the issue is related to their request.
This solution improves the error handling of the API, making it more informative and user-friendly. Developers calling the API with invalid file input will now receive a clear error message indicating that their request was improper, along with a 400 Bad Request status code. This allows them to diagnose and correct the issue more effectively.
try:
result = run(source = os.path.join(app.config['UPLOAD_FOLDER'], filename))
return jsonify({"result":open(result).read()})
except Exception as e:
return jsonify({"Error": "Improper request"+str(e)}),400
Issue Description
Issue Type: Bug/Improvement
Current Behavior
When the API is called with improper request parameters for file input, it responds with a 500 Internal Server Error. However, it is more ideal for developers to receive a 400 Bad Request status code with a meaningful error message when the API call contains invalid file input.
Expected Behavior
The API should be updated to handle invalid file input and respond with a 400 status code (Bad Request) along with a proper error message that guides developers on what went wrong with their request.
Steps to Reproduce
To reproduce the issue:
Suggested Solution
Before fix:
After Fix