fix(api): Differentiate between setup and processing errors #369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improved error handling in the
/api/input_task
endpoint by distinguishing between failures during service initialization and errors that occur during task processing.Previously, any exception was caught and returned as a 400 Bad Request. This was misleading, as a failure to initialize the kernel or agents is a server-side issue (5xx), not a client-side one (4xx).
The logic is now wrapped in separate
try...except
blocks. Failures during the setup phase will correctly return a 500 Internal Server Error, providing a more accurate and actionable error response for both the client and for system monitoring.Purpose
/api/input_task
endpoint were incorrectly reported to the client as a400 Bad Request
.500 Internal Server Error
for server-side exceptions, providing clearer and more accurate error feedback.4xx
) and a server failure (5xx
).finally
block to ensure external client connections are closed, preventing potential resource leaks during an error state.Does this introduce a breaking change?
Note: This is marked as a breaking change because the HTTP status code for a specific failure scenario (service initialization failure) has changed from
400
to500
. This is a corrective change that improves the API's contract, but clients may need to adjust if they were improperly handling this server-side error as a client-side one.PR Title Recommendation:
fix!: api: Differentiate between setup and processing errors
How to Test
* Get the code
Set up the backend environment as per the project's documentation (e.g.,
pip install -r requirements.txt
).Test the code
Test the success case:
/api/input_task
endpoint.200 OK
response with the plan details.Test the server-error case:
AZURE_SEARCH_ENDPOINT
to an invalid URL)./api/input_task
.HTTP 500 Internal Server Error
with the detail:"Could not initialize services for your request."
. This confirms the fix.What to Check
Verify that the following are valid
/api/input_task
functions correctly and returns a200
status.500
status code, not400
.500
error is clear and does not expose internal implementation details.4xx
status code.Other Information
This change is a foundational fix for API stability and correctness. It ensures the service behaves predictably and follows established web standards for error reporting.