sci-ndp / scidx-api

sciDX API
Apache License 2.0
1 stars 2 forks source link

[Bug] Incorrect default parameters causing 400 error for /stream endpoint #70

Closed rbardaji closed 1 month ago

rbardaji commented 1 month ago

[Bug] Incorrect default parameters causing 400 error for /stream endpoint

Description

When making a POST request to the /stream endpoint using the example provided in Swagger, the request fails with a 400 error and the message "No data streams found matching the criteria." The default parameters in Swagger may be misleading and causing the issue.

Steps to Reproduce

  1. Start the server.
  2. Execute the following curl command:
    curl -X 'POST' \
      'http://127.0.0.1:8000/stream' \
      -H 'accept: application/json' \
      -H 'Authorization: Bearer test' \
      -H 'Content-Type: application/json' \
      -d '{
      "keywords": "temperature,bme280",
      "match_all": false,
      "filter_semantics": []
    }'

Expected Behavior

The server should return a 200 status code with the matching data streams or an appropriate message indicating no matches found without suggesting incorrect default parameters.

Actual Behavior

The server responds with a 400 status code and the following message:

{
  "detail": "No data streams found matching the criteria."
}

Possible Solution

  1. Update the default parameters in the Swagger documentation to reflect realistic and commonly matching criteria.
  2. Improve the error handling to provide more context on why no data streams were found.
  3. Change the status code.

Additional Context

The current default parameters in the Swagger documentation may confuse users and lead to unnecessary errors. Providing clearer examples or adjusting the defaults could improve the user experience.

Andreufb commented 1 month ago

It seems that the behavior you're encountering is expected given the example parameters. The /stream endpoint's primary function is to filter and return data streams based on the criteria provided, such as specific keywords. Since the server is not pre-populated with data streams matching every possible keyword, the example request in Swagger is meant to demonstrate the endpoint's functionality, not guarantee a successful match with the default parameters.

Key Points:

Example Parameters: The parameters used in the Swagger example ("keywords": "temperature,bme280") are intended to illustrate how to format a request, not to match existing data streams. The availability of streams depends on the data stored in your particular instance of the system.

Error Handling: The current error message ("No data streams found matching the criteria.") is designed to inform users that no data streams matched the provided keywords. This message is accurate and provides a clear explanation for the 400 status code.

Status Code Update: To address this issue, we will be changing the status code from 400 to 404, which more appropriately reflects that the requested resource (matching data stream) was not found. This change will be made to close this issue.

Realistic Data: To successfully use the /stream endpoint, users need to provide keywords that are relevant to the data streams stored in their system. The example in Swagger serves as a template, and users are expected to adjust the parameters according to their specific data.

Next Steps:

Customizing Requests: Users are encouraged to customize the request parameters to match the data streams available in their system.

Improving Documentation: We will consider adding a note in the Swagger documentation to clarify that the example parameters may need adjustment depending on the available data.

Given these points, the status code update will be implemented to close this issue. Please let us know if you have any additional questions or if further clarification is needed.

Andreufb commented 1 month ago

done