Feature request: return the number of failed attempts
Problem
You allow a parameter "max_retries". It would be great to return along with the API answer the number of "failed" API calls so that people have an idea of the load. I don't know what your policy towards outside contributions is but if you agree I can implement it.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Enhance API to Return Number of Failed Attempts
Currently, the API does not track or return the number of failed attempts when the 'max_retries' parameter is utilized. This limits users' ability to understand the load and performance of their requests, as they cannot see how many retries were made before a successful response or failure.
Awaiting Verification
Be the first to verify this fix
- 1
Modify API Response Structure
Update the API response structure to include a new field 'failed_attempts' that counts the number of failed attempts before a successful response is returned.
pythonresponse['failed_attempts'] = retries_count - 2
Implement Retry Logic
Ensure that the retry logic correctly increments the 'failed_attempts' counter each time a retry is made. This should be done in the section of the code where the API call is made.
pythonif not success: retries_count += 1 - 3
Update Documentation
Revise the API documentation to reflect the new 'failed_attempts' field in the response. Include examples of how this data can be utilized by users.
N/AN/A - 4
Conduct Unit Tests
Create unit tests to ensure that the 'failed_attempts' counter works correctly under various scenarios, including successful calls, failures, and retries.
pythondef test_failed_attempts(): assert response['failed_attempts'] == expected_count
Validation
To confirm the fix worked, make API calls with varying success rates and check the response for the 'failed_attempts' field. It should accurately reflect the number of failed attempts before a successful response.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep